OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] Macro for button to open a Form in Base

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
kabing
OOo Enthusiast
OOo Enthusiast


Joined: 25 Apr 2007
Posts: 179

PostPosted: Tue Oct 02, 2007 4:53 pm    Post subject: [Solved] Macro for button to open a Form in Base Reply with quote

In this thread in the Base forum, I found the following code for opening a form (so I can put a button on another form that will open the second form):



Code:
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_Locations_Data_Entry( oev as variant )
sFormName = "Locations_Data_Entry"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub


I get a Script framework error on the Open_Form_Locations_Data_Entry. Something about the wrong number of paramters. The only thing I've changed is the form name.

If anyone can see what I did wrong, please let me know. Keep in mind I'm pretty clueless when it comes to macro.

Thanks,

kabing

Edit: I forgot to say that I posted this same question in the thread I provided above. But noone there has answered me over the last two weeks. So I'm hoping someone here can help me out.


Last edited by kabing on Wed Oct 03, 2007 3:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Wed Oct 03, 2007 7:02 am    Post subject: Reply with quote

when you call the function 'OpenForm_Locations_Data_Entry', did you pass the oev parameter? when you bind this function to a UI element (such as form button) this parameter is required in the function declaration, and is passed automatically. however, if you call it from another function/sub you need to pass it manually.
Back to top
View user's profile Send private message Visit poster's website
kabing
OOo Enthusiast
OOo Enthusiast


Joined: 25 Apr 2007
Posts: 179

PostPosted: Wed Oct 03, 2007 3:33 pm    Post subject: Reply with quote

QuazzieEvil,

Thank you so much for your answer. I must admit that I didn't understand all of it, but that's o.k. What I did understand pointed out my error. I was trying to test the macro by choosing Tools>Macros>Run Macro. I had not yet assigned it to a button.

As soon as I created a button and added it to my form, it worked perfectly.

Thanks again,

kabing
Back to top
View user's profile Send private message
k443fte
Newbie
Newbie


Joined: 04 Oct 2007
Posts: 2

PostPosted: Thu Oct 04, 2007 6:11 am    Post subject: Having trouble making this macro work! Reply with quote

I am trying to use the macro below:

sub OpenForm_Locations_Data_Entry( oev as variant )
sFormName = "Locations_Data_Entry"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub

When i run this from the my macro screen directly nothing happens no errors and no from opens. I tried adding this macro to module1 main which appears to run the macro when the application starts i get the following error.
"A Scripting Framework error occurred while running the basic script vnd.sun.star:standard.module1.Main?languagebasic&location=application.
Message: BasicProviderIMPL::getscript: no script!"

I am new to base i ave createda database and a few forms just looking to create a form t use as a main menu to enable me to open the other forms using buttons, getting no where i suspect i am missing something major here??

Any ideas greatly recieved Thanks.
Back to top
View user's profile Send private message
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Thu Oct 04, 2007 6:35 am    Post subject: Reply with quote

to run a macro directly from the IDE (basic editor) it will execute a sub called main. to run any code of your own, you must call it there. if the module does not have a sub called main, this may be the problem.
Back to top
View user's profile Send private message Visit poster's website
kabing
OOo Enthusiast
OOo Enthusiast


Joined: 25 Apr 2007
Posts: 179

PostPosted: Thu Oct 04, 2007 6:58 am    Post subject: Reply with quote

k443fte:

Did you include the first part of the code I posted? (From REM Generic Macros... on down)

The form-specific macro (the one you posted) needs those others to work properly, as they define the functions it uses.

kabing
Back to top
View user's profile Send private message
k443fte
Newbie
Newbie


Joined: 04 Oct 2007
Posts: 2

PostPosted: Fri Oct 05, 2007 3:12 am    Post subject: Thanks for the reply, still need further advise. Reply with quote

I have now pasted the entire code into the basic editor, i am now getting the following error when running the macro.

"Basic runtime error
Argument is not optional"

This error is reported against line:

aProp(0).Value = oConnection

Apologies i am a macro monkey!
Back to top
View user's profile Send private message
Billyray
OOo Enthusiast
OOo Enthusiast


Joined: 06 Mar 2007
Posts: 144
Location: Lake Erie's Shore in Ohio

PostPosted: Tue Oct 30, 2007 5:55 pm    Post subject: Reply with quote

"A Scripting Framework error occurred while running the basic script vnd.sun.star:standard.module1.Main?languagebasic&location=application.
Message: BasicProviderIMPL::getscript: no script!"

I am also getting this error message. The only thing I have done is upgrade from version 2.2 of Base to version 2.3. This button always worked perfectly in Base 2.2. When I edit the form's button by simply selecting what's already there, and then saving everything, the button works great again. But when I close Base and re-open Base, I get the error message again and have to do everything over again. I am completely at a loss.
_________________
Billyray
using:
Linux distro: Ubuntu 10.04 LTS, Lucid Lynx, OOo Base 3.3, connected to MySql database using Java jdbc (note: ONLY sun-java-6-1.6.0_22 jre works right), and converted from MS Access 2003.
Back to top
View user's profile Send private message
Thesco_Brasil
Newbie
Newbie


Joined: 15 Jan 2008
Posts: 4

PostPosted: Wed Jan 16, 2008 12:25 pm    Post subject: Reply with quote

Try this:

1) In the screen of DAtaBase (where you create, tables, querys, reports..), go to Tools>options
2) In the first option (openoffice.org), select "ways", (it wiil open a second screen with many ways to files that OOo uses), select "BASIC" and looking for if the way put there is like this "C:\Arquivos de programas\OpenOffice.org 2.0\share\basic; C:\Documents and Settings\t1006669\Dados de aplicativos\OpenOffice.org2\user\basic" (Obs: in my case the OOo is installed with portuguse suport)(Obs: this is the user)
3) If those two ways are pointed, you need to create a module and create a code in this module to OOo can "see" your macro.
4) Case not you will need to point these ways. Clicking in button "Edit" and them "Add", and put the way. Doing that, OOo will see your macros

Remembering that this ways serve for Windows user, and the second way will be maybe oculted.

I hope that it has helped
Back to top
View user's profile Send private message Send e-mail MSN Messenger
BrunoBaena
General User
General User


Joined: 02 Jan 2008
Posts: 5

PostPosted: Fri Apr 11, 2008 6:12 am    Post subject: Open Form Reply with quote

I'm trying to run this code.

But when I click the button, the form open and close immediately.

Did anyone have an idea?
Back to top
View user's profile Send private message
mmetelko
General User
General User


Joined: 12 May 2008
Posts: 16

PostPosted: Sat May 17, 2008 5:17 pm    Post subject: Reply with quote

I have never done with macros before. Could someone tell me how to use this code on a button?

I think i added it into macros base properly, but im not sure how to assign macro to a button properly and how to select which form to open.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group