[Solved] Open another form from the original one

Creating and using forms
Post Reply
User avatar
NiksaVel
Posts: 91
Joined: Fri Jan 25, 2008 12:00 pm
Location: Croatia

[Solved] Open another form from the original one

Post by NiksaVel »

Hi,

I'm having a problem with opening a form from a button for some reason... I've found multiple posts with macro code that's to be mapped to a button to open a form....
for some reason I get an error with each and every one of them.... here's the code I'm using:

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'. One is needed for each form you wish to open from another form. 
sub OpenForm_unos( oev as variant ) 
sFormName = "Admin_Nalazi_unos" 
OpenForm( getFormsTC, getConnectionTC, sFormName ) 
end sub
as far as I understand the code it's supposed to open the form Admin_Nalazi_unos from my database and I assigned this macro to the "main menu" form I've created, but when I click the button I get an error...

BASIC runtime error.
An exception occured
Type: com.sun.star.lang.IllegalArgumentException
Message: .


and it's pointing to:
OpenForm = formContainer.loadComponentFromURL(sFormName,"_blank",0,aProp())
Last edited by Hagar Delest on Tue Jun 10, 2008 2:53 pm, edited 2 times in total.
Reason: tagged the thread as Solved.
OOo 3.1.X on Ubuntu 8.x + Linux Mint 7, Win XP, Vista
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open another form from the original one

Post by Villeroy »

Code: Select all

sFormName = "Admin_Nalazi_unos" 
assumes a distinct form name.
Possibly your database has not such form. I would replace "sub OpenForm_unos" with a more generic sub:

Code: Select all

sub OpenForm_Button_Click( oev as variant )
sFormName = oev.Source.Model.Tag
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub
This reads the name of the form to be opened from the tag of the calling button ("Additional Information" in the button's control properties), so you don't have to adjust code for each different form name.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
NiksaVel
Posts: 91
Joined: Fri Jan 25, 2008 12:00 pm
Location: Croatia

Re: Open another form from the original one

Post by NiksaVel »

thanks for the useful tip!

it still wouldn't work, but then I tried a shorter name and renamed the form to just "unos" and now it works... seems it doesn't like the long form name or the "_"


thanks again!!!
OOo 3.1.X on Ubuntu 8.x + Linux Mint 7, Win XP, Vista
User avatar
NiksaVel
Posts: 91
Joined: Fri Jan 25, 2008 12:00 pm
Location: Croatia

Re: [Solved] Open another form from the original one

Post by NiksaVel »

I'll just add one more question here...

all the forms open in a new window... is it possible to have the macro open the new form in the same frame, replacing the original form - so that you get like a "browser" experience, instead of a load of open windows on screen?

I was thinking replacin _blank with _self or _parent, but I must be wrong, as it doesn't make ANY difference... :shock:
OOo 3.1.X on Ubuntu 8.x + Linux Mint 7, Win XP, Vista
Post Reply