I have a series of pushbuttons that link to other forms in my database.
Every time i click on the pushbutton it goes straight to the first record and i have to keep clicking next to get to the record relevant to what i have open in the first form.
How can I get them to open up to that same record but in the other form?
[Solved] PushButtons opening to active record
[Solved] PushButtons opening to active record
Last edited by xhm100 on Fri Jul 11, 2008 4:55 am, edited 1 time in total.
OOo 2.4.X on Ubuntu 8.x + Windows XP
Re: PushButtons opening to active record
Hello i had a similair challange
The first step is to get control to the original and new form ad the same time. I use the following macro (used by the button)
After you have control to the old (oForm) and new (oNewForm) forms you can set a filter on form by "oNewForm.filter = "?????"
Maybe this helps, good luck
The first step is to get control to the original and new form ad the same time. I use the following macro (used by the button)
Code: Select all
Sub onClickOpenForm ( oEvent as variant )
Dim oNewDoc, oComponent
Dim oForm
oForm = oEvent.Source.Model.Parent
oNewDoc = OpenForm(oEvent, "workpackage")
'get reference to new Form
oNewForm = oNewDoc.drawpage.Forms.getByIndex(0)
'oNewForm.filter = "????"
'get reference to components of Form
oComponent = oNewForm.getByName("project")
oComponent.setString( "test example")
End sub
Function OpenForm( oEvent as variant, aFormName as string) as variant
Dim args(1) As New com.sun.star.beans.PropertyValue
Dim container as variant
Dim oCon
oForm = oEvent.Source.getModel().getParent()
oDoc = getDocumentFromForm( oForm)
oCon = oDoc.Drawpage.Forms(0).ActiveConnection
container = oDoc.Parent.getFormDocuments()
args(0).Name = "ActiveConnection"
args(0).Value = oCon
args(1).Name = "OpenMode"
args(1).Value = "open"
OpenForm = container.loadComponentFromURL(aFormName,"_blank",0,args())
End Function
Function getDocumentFromForm(oForm)
Dim x
Dim sForm$ : sForm = "com.sun.star.form.FormComponent"
Dim sDoc$ : sDoc = "com.sun.star.document.OfficeDocument"
If NOT oForm.supportsService(sForm) Then
Exit Function
End If
x = oForm
Do While NOT x.supportsService(sDoc)
x = x.getParent()
Loop
getDocumentFromForm() = x
End Function
Maybe this helps, good luck
OOo 2.4.X on Ms Windows XP
Re: PushButtons opening to active record
Ahhh. Sorry I'm not sure how to do this. Rather new to base. The two forms I'm dealing with are Projects_Summary as the original form, and my five buttons link to Projects_CAG, Projects_Design etc. What changes would I need to make to the macro?
OOo 2.4.X on Ubuntu 8.x + Windows XP
Re: PushButtons opening to active record
PLease let me know more about your forms
i asume that you have a form with data connected to a table with an interger primairy key called project_id
the project_id from the origenal Form can be used to set a filter in the new form (see below)
I inserted your formname in the macro (see below)
i asume that you have a form with data connected to a table with an interger primairy key called project_id
the project_id from the origenal Form can be used to set a filter in the new form (see below)
I inserted your formname in the macro (see below)
Code: Select all
Sub onClickOpenForm ( oEvent as variant )
Dim oNewDoc, oComponent
Dim oForm
oForm = oEvent.Source.Model.Parent 'this form Projects_Summary with the butto to open new form
vColumn = oForm.findColumn("project_id")
vId = oForm.getInt( vColumn)
oNewDoc = OpenForm(oEvent, "Projects_CAG")
'get reference to new Form
oNewForm = oNewDoc.drawpage.Forms.getByIndex( vId)
vFilter = "( ""Id""= " & vId & ")"
oNewForm.filter = vFilter
oNewForm.reload()
'get reference to components of Form if you wanted to change the new Form
'oComponent = oNewForm.getByName("project")
'oComponent.setString( "test example")
End sub
OOo 2.4.X on Ms Windows XP
Re: PushButtons opening to active record
Tutorial on Forms and Base.
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
Hungarian forum co-admin
Re: PushButtons opening to active record
Thanks again Gerard for your help!
This is the macro I used on the pushbutton for my Projects_CAG form so that it would open up to the active record on my main form, Projects_Summary. Linked by the ID field in Projects_Summary and the REF NO field in Projects_CAG.
This is the macro I used on the pushbutton for my Projects_CAG form so that it would open up to the active record on my main form, Projects_Summary. Linked by the ID field in Projects_Summary and the REF NO field in Projects_CAG.
Code: Select all
REM Generic macros needed to open any form
function OpenForm( formContainer as variant, oConnection as variant, sFormName as string) as variant
Dim aProp(1) As New com.sun.star.beans.PropertyValue
aProp(0).Name = "ActiveConnection"
aProp(0).Value = oConnection
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"
OpenForm = formContainer.loadComponentFromURL(sFormName,"_blank",0,aProp())
end function
function getFormsTC() as variant
getFormsTC = thisComponent.Parent.getFormDocuments
end function
function getConnectionTC() as variant
getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection
end function
REM Macro to open specific form called 'Locations Data Entry'.
REM One Macro is needed for each form you wish to open from another form.
sub OpenForm_Projects_CAG( oev as variant )
oForm = oev.source.model.parent
vColumn = oForm.findColumn("ID")
vId = oForm.getInt( vColumn)
MsgBox "Current ref: " & vId
sFormName = "Projects_CAG"
oNewDoc = OpenForm( getFormsTC, getConnectionTC, sFormName )
'get reference to new Form
oNewForm = oNewDoc.drawpage.Forms.getByIndex(0)
oNewForm.filter = "( ""REF NO"" = " & vId & ")"
MsgBox oNewForm.filter
oNewForm.reload()
end sub
OOo 2.4.X on Ubuntu 8.x + Windows XP