Page 1 of 1
Load a form from other
Posted: Wed Apr 12, 2017 12:13 am
by arfgh
Is it possible to load a form from other, for example having a table grid into and we want to click on some wow and other form get loaded ?
how to do it ?
thx in advance
Re: Load a form from other ?
Posted: Wed Apr 12, 2017 11:43 am
by Villeroy
This is what subforms do. If there is a problem with screen space, you can scroll to the subform by hyperlink or you can write a macro to open another form document and pass the current record ID to the contained form.
Re: Load a form from other ?
Posted: Wed Apr 12, 2017 11:52 am
by arfgh
Villeroy, i use subforms, usually to show filtered data conforming the main form. But i wanted, for example, to click on some row on the table grid into the sub-form, and by the way open 'specialized' form i have designed just on that db record.
Can you please show an example to do it ?
thx in advance
Re: Load a form from other ?
Posted: Wed Apr 12, 2017 11:59 am
by Villeroy
Write a program. You can not expect that someone does that for you over and over again.
We have a whole subforum only for database expamples. With a little bit of searching you could have found this:
viewtopic.php?f=100&t=36124
Re: Load a form from other ?
Posted: Wed Apr 12, 2017 12:56 pm
by arfgh
maybe i have expressed it bad, maybe the better way is to have some button with a macro doing some query and loading the results in the current form. Simpliest to open other forms i think. Using filters that can be easily done, but, when we want to open other form, is with the intention to show the clicked element, and that's my problem, i dont know how to do that...
help
Re: Load a form from other ?
Posted: Sun Apr 16, 2017 1:20 pm
by Nocton
Assign this code to your command button. Delete second line if you don't want to close the first form
Code: Select all
sub FormButton
ThisDatabaseDocument.FormDocuments.GetByName("NewForm").open
ThisDatabaseDocument.FormDocuments.GetByName("OldForm").close
end sub
Or a more comprehensive/universal solution is below. To use this, assign the command button's 'Mouse button released' event to it and if you want to close the calling form add its name to the 'Additional information' property of the button.
Code: Select all
sub OpenFormCloseForm_Button_Click( oev as variant )
'reads sOpenFormName & sCloseFormName separated by a comma from tag of calling button
Dim XX, sOpenFormName, sCloseFormName as string
Dim N1,N2 as integer
XX=oev.Source.Model.Tag
N1=len(XX)
N2=instr(XX,",")
If N2<>0 then
sOpenFormName = left(XX,N2-1)
sCloseFormName = right(XX,N1-N2)
else
sOpenFormName = XX
sCloseFormName = ""
endif
OpenForm( getFormsTC, getConnectionTC, sOpenFormName )
If sCloseFormName<>"" then ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close
end sub
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