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

Need Macro to Open a Form
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
dniezby
OOo Enthusiast
OOo Enthusiast


Joined: 01 May 2004
Posts: 102

PostPosted: Fri Feb 04, 2005 10:59 pm    Post subject: Need Macro to Open a Form Reply with quote

I'm working with BASE and I was building a Main Menu page to find out, that there doesn't seem to be a way to make the BUTTON I created open up a Form from the database?

Anyone have or know how to create a Macro to open a form?
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Feb 07, 2005 7:39 am    Post subject: Reply with quote

I have also been unable to open a form from a Base document using a Macro. I can obtain the Form from a database, but I do not know how to display it.... Frank probably knows how to do it, but I only see him post on the dev mailing list. If you find an answer on your own, please post the answer here as well.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Rockj
Newbie
Newbie


Joined: 31 Jan 2005
Posts: 4

PostPosted: Tue Feb 08, 2005 12:05 am    Post subject: Bad sollution but a temporary fix? Reply with quote



PS: It's not related to macro's or anything but your atleast able to open up the new forms Rolling Eyes
PS2: Take note that it's saving it's path in fullpath which is a bad sollution too :/ So I'm currently also searching for another sollution.
[/img]
Back to top
View user's profile Send private message
dniezby
OOo Enthusiast
OOo Enthusiast


Joined: 01 May 2004
Posts: 102

PostPosted: Fri Feb 11, 2005 8:07 pm    Post subject: Reply with quote

What about a Macro to Simply open a document MAXIMIZED?
Anyone know how to do that one easily?

At least if I can get the document to open Maximized the form will be properly viewed on most monitors.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Sat Feb 12, 2005 8:15 pm    Post subject: Reply with quote

I found out how to do this in the new beta Smile OK, it was not really me... I asked on the dev list. It turns out .....
Code:
oDatabaseDocument::XFormsSupplier.getForms().loadComponentFromURL(
  <relative_form_url> )

Had not thought about it...
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
dniezby
OOo Enthusiast
OOo Enthusiast


Joined: 01 May 2004
Posts: 102

PostPosted: Sun Feb 13, 2005 11:52 am    Post subject: Reply with quote

See, here is the problem...I'm trying to create a local application not something that would be run over the net. I wouldn't have a URL.
So, this being the case, how would I open a document that's on a local drive???
I 'm new to this type of coding so I'm still learning BUT isn't there a way to write a URL using something like :
Code:

%localdirectory%/docs/document_to_open.odb


So in this command line it would be done this way:
Code:

oDatabaseDocument::XFormsSupplier.getForms().loadComponentFromURL(
  <"%local%/docs/document_to_open.odb">
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Feb 14, 2005 7:03 am    Post subject: Reply with quote

Quote:
See, here is the problem...I'm trying to create a local application not something that would be run over the net. I wouldn't have a URL. So, this being the case, how would I open a document that's on a local drive???

Umm, well, if it is running over the net then what good is it to access the local drive Smile
I assume that you need to know where your documents are, or you need to have the user select the document in question.
Quote:
I 'm new to this type of coding so I'm still learning BUT isn't there a way to write a URL using something like : %localdirectory%/docs/document_to_open.odb

Read the section titled "Get and set the current directory" in my free macro document.
Quote:
So in this command line it would be done this way:
oDatabaseDocument::XFormsSupplier.getForms().loadComponentFromURL(
<"%local%/docs/document_to_open.odb">

Well, after you open your database document, and you may have to do this from the connection, I have not tried this.... so, I do not know yet if it is oDoc.getForms.loadComponentFromURL() or if it is oCon.getForms.loadComponentFromURL(), but it should be a simple test fo find out. I have just not gotten that far with my database experiments.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
dniezby
OOo Enthusiast
OOo Enthusiast


Joined: 01 May 2004
Posts: 102

PostPosted: Mon Feb 14, 2005 8:14 am    Post subject: Reply with quote

I have your ebook and I'm looking through it. Thanks.

I wonder...do you think that it's possible to make a stand-alone application using macros?
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Feb 15, 2005 8:46 am    Post subject: Reply with quote

My ebook? do you mean OpenOffice.org Macros Explained or AndrewMacro? Just curious....

Realize OOo macros run from inside of OpenOffice.org. I am not aware of any way to package these as a stand alone runtime. Also, programs that manipulate the OOo API connect to a running OOo server.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Tue Feb 15, 2005 12:33 pm    Post subject: Reply with quote

dniezby:
No, because object files are generated internally (buried into OpenOffice).
As Andrew said OpenOffice acts as the server and there is currently no way to convert OOo macros into stand-alone programs.

But I wonder why you would wanna do that? Starbasic is not that much different from VisualBasic but does not have that much OS (MS Windows respectively) power than VB, or in other words: It's not that general, because it only runs along with OOo.
On the other hand VB is not that general as well, because of no support for other platforms than Microsoft Windows, so Python or Perl might be strongly considered if you want to target multiple platforms and do some easy programming.

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Tue Feb 15, 2005 7:02 pm    Post subject: Reply with quote

There are probably better ways of doing things than this but the code below appears to work. I haven't yet looked into how to change the records displayed.
What I am not sure about is where to put the code. I can put it into a library associated with the OOo installation BUT to me it would make more sense if it was in the .odb file. I can't see how to have a library directly associated with a .odb file (only checked the UI) and libraries in forms don't appear to get saved (OOo1.9.77 for Linux).
Code:

sub subDisplayForm(sDatabaseName as string, sFormName as string)
dim mArgs(1) as new com.sun.star.beans.PropertyValue

oDatabase = fnGetOpenDatabase(sdatabaseName)
oConnection = oDatabase.getConnection("","")
mArgs(0).name = "OpenMode"
mArgs(0).value = "open"   '"openDesign"   '   '"openForMail"
mArgs(1).name = "ActiveConnection"
mArgs(1).value = oConnection
oForm = oDatabase.getFormDocuments.getByName(sFormName)
'oForm.visibilityChanged(true)
oDatabase.getFormDocuments.loadComponentFromURL(sFormName, _
   "_blank", 0, mArgs())
end sub


function fnGetOpenDatabase(sDatabaseName as string)
oEnum = StarDesktop.getComponents.createEnumeration
while oEnum.hasMoreElements
   oPosDB = oEnum.nextElement
   if oPosDB.implementationName = "com.sun.star.comp.dba.ODatabaseSource" then
      if right(oPosDB.name, len(sDatabaseName)) = sDatabaseName then
         fnGetOpenDatabase = oPosDB
         exit function
      end if
   end if
wend
end function

_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Feb 15, 2005 9:26 pm    Post subject: Reply with quote

Quote:
I can't see how to have a library directly associated with a .odb file

You can not!... See http://qa.openoffice.org/issues/show_bug.cgi?id=40711 One thing that was said....
Quote:
a database document does not allow for scripting - you cannot embed macros in
it, so where would you expect "thisComponent" to be useful?
What you can do is embed macros in the forms/reports within a database document.
In those macros, "thisComponent" refers to the form/report itself, which does
make sense. Currently, there is no possibility to access the database document
within such macros, but this is fixed by issue 40358.

_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
nimo
General User
General User


Joined: 15 Feb 2005
Posts: 10
Location: Netherlands

PostPosted: Wed Feb 16, 2005 1:37 am    Post subject: Reply with quote

i'm also looking for a way to open new Forms with a button,
so is that the code i need to have?
Back to top
View user's profile Send private message
evershade
General User
General User


Joined: 03 May 2004
Posts: 24

PostPosted: Sat Mar 12, 2005 10:08 pm    Post subject: open form programmatically in 2.0 Reply with quote

lannz,

your method seemed to work at first. but now the form window opens for a blink and then it's gone again. also, 2.0 has taken to crashing after a few attempts.

it's... almost... there...

:o)
Back to top
View user's profile Send private message
evershade
General User
General User


Joined: 03 May 2004
Posts: 24

PostPosted: Mon Mar 14, 2005 5:21 pm    Post subject: Reply with quote

tried creating a new database and encountered similar behavour. the code worked to open a form the first few times but then i get one of the following:

- the form window opens for a split second, then closes
- 2.0 crashes entirely

if i place a breakpoint on or before the line:


Code:
oDatabase.getFormDocuments.loadComponentFromURL(sFormName, _
   "_blank", 0, mArgs())


and step thru one line at a time, the form window will stay open until i reach the 'end sub' statement and then close. it appears the form is somehow cotained in the subs memory space and then wiped out upon completion.
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
Goto page 1, 2  Next
Page 1 of 2

 
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