[Solved] Auto open form

Creating and using forms
Post Reply
sugarplum
Posts: 3
Joined: Fri Jun 05, 2009 5:24 pm

[Solved] Auto open form

Post by sugarplum »

How do i create a macros to auto open a form called 'Address', when database opened?

Ive been trying for days to get this to work and i'm now about to give up!!

Please help!
Last edited by Hagar Delest on Sun Jun 14, 2009 12:04 am, edited 1 time in total.
Reason: tagged [Solved].
OOo 2.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Auto open form

Post by Villeroy »

Open the form.
menu:File>Save As ... anywhere you like (desktop?).
Close the form and load the stored file instead.
menu:View>Toolbars>FormDesign
Turn on design mode (button #2)
Get the form's properties (button #4), tab "Data"
If the database is registered pick the name from listbox "Data Source", else push the [...] button near that list box and point to the odb file where the form originated from. Restore the other data settings (which table, query or SQL).
Turn off design mode and save the file.
If the form works as expected, close the document and get your preferred file manager.
Remove all write access from the file.
Open the new Writer document with the form connected to the database. The document loads write-protected like the embedded form to prevent the form itself from changes. The form and it's controls work as expected.
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
sugarplum
Posts: 3
Joined: Fri Jun 05, 2009 5:24 pm

Re: Auto open form

Post by sugarplum »

Youre a star!!!


Thank you so much, its been doing my head in. Now this is a bit cheeky but can i now add three macros to this form? All three to open reports that use queries and will continually change. The reports basically sifts the address book data for customers, non customers and n/a. Is it possible to add button like in access?


Cheers
OOo 2.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Auto open form

Post by Villeroy »

I tried to answer your initial question, opening a connected ODF document with forms instead of an embedded form.

No, nothing is like MS Access here. Base mimics a single-file database in a very broken way. I'd always recommend using any mature database and use Base as additional frontend, separated from the backend, possibly with some stand-alone input forms.
The whole office suite is about spreading the ODF file format. The Base component is an addition to import external tabular data into ODF documents (all forms and reports are Writer docs), the forms are a joke and the self-contained, single-file database is a desaster. Do not use it except for playground databases, demos and learning SQL.
If you ever want to use some data in ODF documents, connect Base to it, add some appropriate SELECT queries, register the database and drag your stuff into office documents (Writer or Calc, since v3.0 even Impress).
Do not use the GUI to manipulate the backend's structure. You may destroy your database.
It's not always your fault, if the "query designer" does not produce valid queries, simply use plain SQL.
You can use the core of the office suite with Base as a bridge to print out formatted database data and calculate imported record sets in spreadsheets (including pivot tables). I use Calc as my preferred simplified report engine. I was too disappointed by Sun Report Builder 1.0 to 1.0.5.
In short. Use Base as a configuration-bridge, but avoid all of it's graphical tools.

Writing macros based on this over-the-top complex API is a nightmare, particularly if you find inconsistancies and bugs in literally every project you try to start. OOo Basic is strictly procedural and thus completely inadequate to deal with database object, form controls in particular.
Since v.3.1 you can embed stupid Basic in database documents. Before that version you could embed Basic in forms and reports and turn off all macro security to avoid security prompts. A form that is not embedded in the Base-jail can have macros just like any other document (and it can have subforms connected to other databases, btw).
You can find a switchboard extension under http://extensions.services.openoffice.org. I don't like it. It's make-up for an iherently ugly thing. I can live with the database window as switchboard.
SInce v3.1 there are new API-methods to open forms and reports more reliably from simple Basic code. Shurely you may find some way to filter a report by means of Basic. You may even find someone who shares some code for this.
I prefer to filter a report by the backend. It seems to be faster, less memory consuming and it does not require any code.
http://user.services.openoffice.org/en/ ... hp?id=6442
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
sugarplum
Posts: 3
Joined: Fri Jun 05, 2009 5:24 pm

Re: Auto open form

Post by sugarplum »

Thanks for the heads up. I think i'm all but done, and i wouldnt have been able to do it without your advice. So thank you.

Sarah
mark_orion
Posts: 38
Joined: Thu Oct 02, 2008 11:53 am

Re: [Solved] Auto open form

Post by mark_orion »

I solved the problem with the following macro that I assigned to the "Open Document" Event via Tools / Customize:
Sub Main
dim sqlconnection as variant
dim formContainer as variant
dim aProp(1) As New com.sun.star.beans.PropertyValue
sqlconnection = thisDatabaseDocument.DataSource.getConnection("","")
aProp(0).Name = "ActiveConnection"
aProp(0).Value = sqlconnection
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"
formContainer = thisDatabaseDocument.FormDocuments
formContainer.loadComponentFromURL("PutYourFormNameHere","_blank",0,aProp())
End Sub
OOo 2.4.X on Ubuntu 8.x
djskafish
Posts: 11
Joined: Tue Dec 01, 2009 11:02 pm

Re: [Solved] Auto open form

Post by djskafish »

This doesn't work with a Switchboard. I have found Macro codes, but they have one nasty glitch: they open your switchboard ANY time you open ANY component of OOoBase. Any suggestions?
Windows XP Professional en Español, OOo 3.1
Post Reply