| View previous topic :: View next topic |
| Author |
Message |
JAnneP General User

Joined: 18 Aug 2007 Posts: 39 Location: Ontario
|
Posted: Sat Jun 28, 2008 1:51 pm Post subject: Automating Base application start-up for end users |
|
|
| I am working on my first Base application, and I would like the users to be able to start up the application from an icon, and go directly to the application forms (ie. not the ooBase development environment). Is this possible? If so, could someone give me an example to show how it is done? |
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Wed Jul 02, 2008 7:00 am Post subject: |
|
|
Hi JAnneP,
Yes this is possible. To have a stand alone form there are several steps involved.
1. With your form operating (not design mode) go to file menu and do a "save as" and put a copy on your desktop.
2. Launch it and go to "toolbars" and turn on the "form design" toolbar.
3. You can now go into "design mode" where you need to select the data source for each of your mainforms and subforms in your "writer doc" form.
Use the "form navigator" from the "form design" toolbar to do this as you can go directly to the properties of each form. For example, in the data properties of your mainform there is now a new dropdown where you select the data source. Don't forget to check each of your controls and reselect their datafields if they have dropped off.
If you want to create a switch board form to launch your other forms it is a little more complicated than this. You will need some macro's to help out here. This is a macro I am using at the moment for this, the bulk of which I got from this forum.
I have modified it a little to work from an "outside" form (such as a switchboard) due to the failings of using "ThisComponent" in such situations. (see the getFormsTC function)
You then just need then a button on your switch board who's event triggers the "OpenForm_Form1" sub. Of course you need to customize the form names and put your database name in and add more "OpenForm" subs for the number of forms you want to launch.
| 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())
Rem... customize for your screen size
With OpenForm.GetCurrentController().GetFrame().GetContainerWindow()
.SetPosSize(0,0,,,com.sun.star.awt.PosSize.POS)
.SetPosSize(,,1440,860,com.sun.star.awt.PosSize.SIZE)
End With
end function
Rem... modified to work from "stand alone" form. Using "ThisComponent" was crashing the function so this done...
function getFormsTC() as variant
dim Context as object
dim DB as object
dim conn as object
Context=CreateUnoService("com.sun.star.sdb.DatabaseContext")
DB=Context.getByName("dataBase_Name")
Conn=DB.getConnection("","")
getFormsTC = conn.parent.databasedocument.getFormDocuments
end function
function getConnectionTC() as variant
getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection
end function
REM Macro to open specific form called Form1. One is needed for each form you wish to open from another form.
sub OpenForm_Form1
sFormName = "Form1"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub
REM Macro to open specific form called 'Form2'. One is needed for each form you wish to open from another form.
sub OpenForm_Form2
sFormName = "Form2"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub |
more reading here...
http://www.oooforum.org/forum/viewtopic.phtml?t=43480
Cheers
Voo |
|
| Back to top |
|
 |
JAnneP General User

Joined: 18 Aug 2007 Posts: 39 Location: Ontario
|
Posted: Wed Jul 02, 2008 8:10 am Post subject: |
|
|
Thanks for the information! I have a few questions, though. I found this OpenForm code on the forum too, and have incorporated it into my application to open forms from other forms. I am using the following getFormsTC function:
function getFormsTC() as variant
getFormsTC = thisComponent.Parent.getFormDocuments
end function
This works fine from within an application, when you are getting another form in the application. I understand that your modifications would enable you to work with a form that was not part of the current application. You mention in your code comments that you have modified the function to get around some problems. Does this mean that I would be better to switch to your modified getFormsTC function, even though the original one seems to be working OK for me?
Secondly, you have explained how to start a db application from a Writer document. I got some info on another thread (I think from you, also) which explained how to start an application by running an sbase macro with a desktop shortcut. The macro then opens the main form of the DB application. Which of these 2 methods is better? Is there any situations where you should use one rather than the other?
Finally, I have been playing around with implementing tabs (Access style) to run the various forms in my application. I am using the ideas from another thread involving setting up each application form in a section of the document, and then showing/hiding appropriate sections when the tab buttons are pressed. This seems like a nicer user interface than a splash screen, because the user can flip back and forth from one form to the other easily, and I think the whole thing is more intuitive. Under this scenario, I will end up with a Main form containing tab buttons and several different document sections, each containing a frame in which I will copy one of my application forms. In other words, the entire application will be contained in a single main form. I am assuming I could then save this document as a Writer doc, and follow the instructions you have given above to connect the data sources to the Writer doc, so that when a user opened this document, the entire application would be available to them. Is my understanding correct? If so, do you see any reasons why this kind of implementation would not be a good idea?
BTW, thanks for all your help, and your well-explained forum posts. I have learned an incredible amount from you already
Anne |
|
| Back to top |
|
 |
JAnneP General User

Joined: 18 Aug 2007 Posts: 39 Location: Ontario
|
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Wed Jul 02, 2008 7:23 pm Post subject: |
|
|
Hi JAnneP,
| Quote: | function getFormsTC() as variant
getFormsTC = thisComponent.Parent.getFormDocuments
end function
This works fine from within an application, when you are getting another form in the application. |
Yes, it is fine to use "ThisComponent" when using macros to launch other forms that are all contained within the same database. The problem arises when you are using a "writer doc" form that you have saved external to your database. Even though you have reconnected it to see the datasources of your original database, it is no longer part of the "container" of forms, so there is no "parent" for "ThisComponent" to use to get to the Form Documents container. Instead we need to create a connection to the database ourselves and go to the form container that way.
| Quote: | | Does this mean that I would be better to switch to your modified getFormsTC function, even though the original one seems to be working OK for me? |
No, not at this stage. It would be only necessary for a form that is external to your database used to launch forms in your database. Launched forms would still interact normally via "Thiscomponent.parent..."
Additionally, using the "Creating a connection" method has a downside too. You must remember to change the database name in the code if you ever rename your database. I like to put a REM note at the top of the macro code to remind me that I have used a name in the code that could change. So if you were to use this method everywhere then you would need to be careful if you renamed your database.
I don't know if there are any further downsides to creating a connection like this each time if used as a general method (for example if you should be closing the connections too). QuazzieEvil might know.
| Quote: | | Secondly, you have explained how to start a db application from a Writer document. I got some info on another thread (I think from you, also) which explained how to start an application by running an sbase macro with a desktop shortcut. The macro then opens the main form of the DB application. Which of these 2 methods is better? Is there any situations where you should use one rather than the other? |
The two methods are using a similar concept as in the other sbase macro it is using a "created connection" to the database too. The only difference is that the sbase macro is a bit more condensed and is designed to easily work from a desktop shortcut. It dosen't use "ThisComponent" at all. The macro I have mightn't work from a shortcut without further modification. The screen resizing section could probably be easily added to Quazzie's one.
| Quote: | | I am assuming I could then save this document as a Writer doc, and follow the instructions you have given above to connect the data sources to the Writer doc, so that when a user opened this document, the entire application would be available to them. Is my understanding correct? If so, do you see any reasons why this kind of implementation would not be a good idea? |
Yes, Robby is doing some good work with TABs at the moment. I haven't had time to explore the issue yet but I don't see why you couldn't run such a thing external to the database as long as you reconnected all the data sources. As you would have already needed to modify your macros to work within the one form already I think it would work fine. Hopefully any troubleshooting you needed to do would be minor.
Cheers
Voo
ps.. thanks for your kind words, I do like to help. I am still learning too!  |
|
| Back to top |
|
 |
JAnneP General User

Joined: 18 Aug 2007 Posts: 39 Location: Ontario
|
Posted: Thu Jul 03, 2008 5:48 am Post subject: |
|
|
Thanks again for your detailed and informative reply. It is most appreciated  |
|
| Back to top |
|
 |
tomatosld General User

Joined: 23 Jun 2008 Posts: 6
|
Posted: Thu Jul 03, 2008 8:55 am Post subject: |
|
|
Help! I am using the code above to try to open a form either way - inside the database or from an external document on my desktop (cool trick, if I can get it work, btw) - and I am getting this error message:
BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: .
on line:
OpenForm = formContainer.loadComponentFromURL(sFormName,"_blank",0,aProp())
The blank Message part is particularly helpful to me.
I also tired the plain open form code snippet from a different thread as well to see if it was the external document issue and got the same exact results. I'm not able to open forms at all. I am assuming I have not declared the oConnection variable properly? Or is there some basic package of runtimes I need to install with base that declares these built in functions? |
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Thu Jul 03, 2008 9:23 am Post subject: |
|
|
Hi tomatosid,
I guess, check that you have registered your database in open office. Goto tools>options>openorg.bas>Databases and register it there.
If so, check you have put your form name correctly (including case) in the "openForm_Form1" sub. It is this sub that you link to with your push button "when initiating" event, by the way. Also check your database name is correct case in the connection function.
Also check that you have the HSQL database engine by looking at the bottom of the screen in the base GUI window.
Let me know how you go.
cheers
Voo |
|
| Back to top |
|
 |
tomatosld General User

Joined: 23 Jun 2008 Posts: 6
|
Posted: Thu Jul 03, 2008 9:47 am Post subject: |
|
|
aha!
Yes, when I changed the name of the db, it was no longer registered properly. I knew it was an easy fix and I was just missing something silly.
Thanks Voo! |
|
| Back to top |
|
 |
pmancuso General User

Joined: 04 Jul 2008 Posts: 8
|
Posted: Sun Jul 06, 2008 11:12 pm Post subject: |
|
|
Hey Voo!
I seem to have run into an issue.
I made a writer document and added a button called "names". I then created a new macro and put your code from above inside it. I changed dataBase_Name to my registered database. And I changed form1 to the name of the form I wanted to open within that database.
I then linked the button to the macro "OpenForm_form1" and tried it out.
I tested it and the form opens up! BUT, no data is displayed! Why?I think you explained that part in your original post but I cannot figure it out. I thought I already connected it to the database, yet it dosnt seem to be getting any info from it. Do you have an idea of whats going on? I only changed the two settings, what else was I supposed to change?
Thanks
-John |
|
| Back to top |
|
 |
pmancuso General User

Joined: 04 Jul 2008 Posts: 8
|
Posted: Mon Jul 07, 2008 2:04 am Post subject: |
|
|
Updated
Ok I believe I solved the problem. I opened up the form navigator for my switch board and edited the data source to the registered database that corresponds to the form I wanted to open.
I see how you were talking about that and I thought I did that originally, turns out I didn't.
Saved it and now it displays the data in the form. I'm just posting the solution here (as far as I know) in case anyone else has the problem.
-John |
|
| Back to top |
|
 |
base_jumper Newbie

Joined: 19 Dec 2008 Posts: 1 Location: Colorado, US
|
Posted: Fri Dec 19, 2008 9:53 am Post subject: Code not working for me |
|
|
Hi All-
When I run the macro above, I get an error on line:
aProp(0).Value = oConnection
Error: Basic Runtime Error: Argument is not optional
I've tried tweaking it, but have not worked in Basic in 10+ years. Any help here? What am I not doing correctly???
WinVista, OOo3.0.0m9
Thanks
Tim |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
|
| Back to top |
|
 |
colby@jordan-cu.org General User

Joined: 19 Feb 2009 Posts: 6
|
Posted: Fri Mar 06, 2009 4:25 pm Post subject: |
|
|
Is there a way to edit the code below that was provided by Voobase above to open a report instead of a form? Any help would be appreciated! Thanks
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())
Rem... customize for your screen size
With OpenForm.GetCurrentController().GetFrame().GetContainerWindow()
.SetPosSize(0,0,,,com.sun.star.awt.PosSize.POS)
.SetPosSize(,,1440,860,com.sun.star.awt.PosSize.SIZE)
End With
end function
Rem... modified to work from "stand alone" form. Using "ThisComponent" was crashing the function so this done...
function getFormsTC() as variant
dim Context as object
dim DB as object
dim conn as object
Context=CreateUnoService("com.sun.star.sdb.DatabaseContext")
DB=Context.getByName("dataBase_Name")
Conn=DB.getConnection("","")
getFormsTC = conn.parent.databasedocument.getFormDocuments
end function
function getConnectionTC() as variant
getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection
end function
REM Macro to open specific form called Form1. One is needed for each form you wish to open from another form.
sub OpenForm_Form1
sFormName = "Form1"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub
REM Macro to open specific form called 'Form2'. One is needed for each form you wish to open from another form.
sub OpenForm_Form2
sFormName = "Form2"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub _________________ -Colby |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
|
| Back to top |
|
 |
|
|
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
|