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

How To Load Forms and Reports inside a BASE document

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Tue Dec 20, 2005 6:04 pm    Post subject: How To Load Forms and Reports inside a BASE document Reply with quote

Loading Forms and Reports inside a Base document:
Code:

Sub openBaseForm
   Dim pProp(1) As New com.sun.star.beans.PropertyValue
   sURL = ConvertToURL("C:\Documents and Settings\user1\baseDoc.odb")
   oDoc = starDesktop.loadComponentFromURL(sURL,"_blank",0,Array())
   oForms = oDoc.getFormDocuments()
   oAConnection = oDoc.DataSource.getConnection("","")
   'set properties
   pProp(0).Name = "ActiveConnection"
   pProp(0).Value = oAConnection
   pProp(1).Name = "OpenMode"
   pProp(1).Value = "open" ' OR: openDesign
   ' load the form: TargetFrameName and SearchFlags aren't used
   oFormulario = oForms.loadComponentFromURL("name_of_form","_blank",0,pProp())
End Sub


Same way for Reports, but:
Code:

   oDoc = starDesktop.loadComponentFromURL(sURL,"_blank",0,Array())
   oReps = oDoc.getReportDocuments()
   ' ....
   '
   oReport = oReps.loadComponentFromURL("name_of_report","_blank",0,pProp())


HTH
Back to top
View user's profile Send private message
verycheeky
General User
General User


Joined: 27 Mar 2006
Posts: 5

PostPosted: Sun Jun 11, 2006 7:48 pm    Post subject: Just open form Reply with quote

Hello!
this script works! opens Database and Form! its sooo cool when macros work and no errors!

however.. now i have multiple copies of the same database opened along with forms.

is there anyway to just open the form and not the database associated with it?

Best Regards

M@
Back to top
View user's profile Send private message
bvdbos
OOo Enthusiast
OOo Enthusiast


Joined: 23 Nov 2003
Posts: 140
Location: Asten Netherlands

PostPosted: Mon Aug 14, 2006 6:18 am    Post subject: parent of oDoc is Base? Reply with quote

I'm not in a place to try (will try later) but isn't is something like:

Code:
oForm=ThisComponent.parent
   oForms = oDoc.getFormDocuments()
   oAConnection = oDoc.DataSource.getConnection("","")
   'set properties


etc etc?
_________________
gr

Bas
Back to top
View user's profile Send private message Visit poster's website
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Mon Aug 21, 2006 12:43 pm    Post subject: Reply with quote

Since I posted that snippet a lot of people asked how to open forms and reports without open the parent base document.

Here is how (quick test with OOo 2.0.3 / XPp):
Code:

Sub openOnlyBaseForm

   oContexto = CreateUnoService("com.sun.star.sdb.DatabaseContext")
   oFonte = oContexto.getRegisteredObject("planilha_2_base")
   oForms = oFonte.DatabaseDocument.FormDocuments
   oAConnection = oFonte.getConnection("","")

   Dim pProp(1) As New com.sun.star.beans.PropertyValue
   pProp(0).Name = "ActiveConnection"
   pProp(0).Value = oAConnection
   pProp(1).Name = "OpenMode"
   pProp(1).Value = "open"

   oForm = oForms.loadComponentFromURL("form_CALC2BASE", "_blank", 0, pProp())
End Sub


Reports ( no test ):
Code:

Sub openOnlyBaseReport

   oContexto = CreateUnoService("com.sun.star.sdb.DatabaseContext")
   oFonte = oContexto.getRegisteredObject("planilha_2_base")
   oReports = oFonte.DatabaseDocument.ReportDocuments
   oAConnection = oFonte.getConnection("","")

   Dim pProp(1) As New com.sun.star.beans.PropertyValue
   pProp(0).Name = "ActiveConnection"
   pProp(0).Value = oAConnection
   pProp(1).Name = "OpenMode"
   pProp(1).Value = "open"

   oReport = oReports.loadComponentFromURL("rep_CALC2BASE", "_blank", 0, pProp())
End Sub


HTH
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1145
Location: France

PostPosted: Tue Aug 22, 2006 12:25 am    Post subject: Reply with quote

Danad wrote:
a lot of people asked how to open forms and reports without open the parent base document.
Here is how (quick test with OOo 2.0.3 / XPp)

Thank you for your snippets, Danad Smile
I have a remark on this one. It is in fact impossible to open a form/report integrated in a Base document without opening it. Your interesting code is a quick method, but it is same as loading the Base document in Hidden mode.
On Windows you can see that a lock file appears when you run the macro. If you close the form by hand, the lock file remains. You have to close the hidden Base document to get the lock deleted. So it is necessary to have a global variable containing access to the Base document, and later close it.
Code:
oDoc.close(True)

When you close the Base document, opened forms/reports from this document are also closed.

You can get the source with the usual method
Code:
oFonte = oContexto.getByName("planilha_2_base")
Back to top
View user's profile Send private message Visit poster's website
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Wed Aug 30, 2006 11:31 am    Post subject: Reply with quote

Quote:

I have a remark on this one. It is in fact impossible to open a form/report integrated in a Base document without opening it.

As usual, you're right.
Quote:

Your interesting code is a quick method, but it is same as loading the Base document in Hidden mode.

I'm not sure about this. After loading a document in Hidden mode, it can be enumerated as a component.
Quote:

On Windows you can see that a lock file appears when you run the macro. If you close the form by hand, the lock file remains.

Yes, I saw that. But here after some runs, suddenly, this behaviour was gone and I don't know why.
Quote:

You can get the source with the usual method:

But Smile why not give a try to the others ?

Bernard, yours comments are full of enlightenment.
Thanks.
Back to top
View user's profile Send private message
Roofoos
General User
General User


Joined: 06 Jan 2007
Posts: 16
Location: Bolzano- Italy

PostPosted: Wed Jan 10, 2007 7:53 am    Post subject: Reply with quote

Is it possibile to open "current record position" from a form to another form??

for example, i have a list box, I choose "Roberto", then i click the button "view details" and another form will open directly to "Roberto" record position.

thank you..
Back to top
View user's profile Send private message Visit poster's website
trenkler
Power User
Power User


Joined: 21 May 2005
Posts: 55

PostPosted: Sun Jan 28, 2007 2:44 pm    Post subject: Reply with quote

Roofoos wrote:
Is it possibile to open "current record position" from a form to another form??

for example, i have a list box, I choose "Roberto", then i click the button "view details" and another form will open directly to "Roberto" record position.

thank you..


Yes. You have to open form with something like oForm.filter= variable which shows the record position of Roberto.

juraj
Back to top
View user's profile Send private message
cordelia
Newbie
Newbie


Joined: 11 Oct 2007
Posts: 1

PostPosted: Thu Oct 11, 2007 9:31 am    Post subject: Reply with quote

Here\s a very nice site that points out how to use the Knowledge Base with a schem and everything: https://engineering.purdue.edu/ECN/Support/KnowledgeBase/Docs/20030122170616 .
Cheers
_________________
Many people take no care of their money till they come nearly to the end of it, and others do just the same with their time.-
Goethe
drugs canada
Back to top
View user's profile Send private message
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2599
Location: Cumberland, MD

PostPosted: Sat Oct 27, 2007 7:33 pm    Post subject: Reply with quote

B Marcelly wrote:
Danad wrote:
a lot of people asked how to open forms and reports without open the parent base document.
Here is how (quick test with OOo 2.0.3 / XPp)

Thank you for your snippets, Danad Smile
I have a remark on this one. It is in fact impossible to open a form/report integrated in a Base document without opening it. Your interesting code is a quick method, but it is same as loading the Base document in Hidden mode.
On Windows you can see that a lock file appears when you run the macro. If you close the form by hand, the lock file remains. You have to close the hidden Base document to get the lock deleted. So it is necessary to have a global variable containing access to the Base document, and later close it.
Code:
oDoc.close(True)

When you close the Base document, opened forms/reports from this document are also closed.

You can get the source with the usual method
Code:
oFonte = oContexto.getByName("planilha_2_base")


Hi,

the lock file you are talking about is the file created by the HSQLdb engine. In the case of an embedded database file, then yes the ODB file is opened by the connection manager. The *.lck remaining after the form is closed is only the case if there is any other OpenOffice.org window (object ) open ( this includes the Quckstarter )

This is a known problem where the JRE does not automatically release the connection just because the form has been closed.

One way around this is to explicitly dispose of the variable holding the connection. Kind of the same thing as the global variable for the hidden document. The developers swear that this should not be necessary, but it sure is every time I test it.

One other the thing to remember is that not all ODB files include the embedded database. So if we are connecting to PostgreSQl, for instance, then all the ODB file holds is the definition of the connection, not the data. In this case the form is extracted and the connection created. The ODB file itself should not be opened at this point.

To be honest I am not even sure the ODB file is open, by one definition anyway, even in the embedded model above. If you say you have tested this I'll believe you. But the *.lck file not being deleted when the form is closed does not equate the odb file being open at all.
EDIT - well, gee...I suppose I might be all wet three...LOL...now I am going to have to off and try to test this also...I'll let ya'll know how that goes...
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets 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