[Solved] Open a form from a macro

Discuss the database features

[Solved] Open a form from a macro

Postby dsky » Fri Feb 15, 2008 5:55 pm

I've tried to do this using code examples from many forums, but I always get an error message. Here's my latest effort:
Code: Select all   Expand viewCollapse view
Sub OpenForm(Event As Object)
   Dim Form As Object
   Dim FormDoc AS Object
   Dim FormCollection As Object
   Dim DBDoc As Object
   Dim Args(1) As New com.sun.star.beans.PropertyValue
   Form = Event.Source.Model.Parent


End Sub

I assign this macro to the "Mouse button released" event of a button on a dialog. However, when I run the dialog and click the button, I get a Basic runtime error: "Property or method not found.", pointing to the line "Form = Event.Source.Model.Parent ".

Can someone tell me what I'm doing wrong?

Last edited by dsky on Sat Sep 25, 2010 6:06 pm, edited 2 times in total.
Posts: 7
Joined: Tue Jan 29, 2008 3:59 pm

Re: Open a form from a macro

Postby Echelon » Fri Feb 15, 2008 10:32 pm

I am not certain exactly where you have gone wrong, but here is the code that I use myself.

The following code sets up a function that can be used to open any form.

Code: Select all   Expand viewCollapse view
Sub OpenForm( oEvent as variant, aFormName as string) as variant
  Dim args(1) As New com.sun.star.beans.PropertyValue
  Dim container as variant

  container = oEvent.Source.Model.Parent.ActiveConnection.Parent.DatabaseDocument.FormDocuments

  args(0).Name = "ActiveConnection"
  args(0).Value = oEvent.Source.Model.Parent.ActiveConnection
  args(1).Name = "OpenMode"
  args(1).Value = "open"

End Sub

Next you need to add a function that will call this first function and pass it the name of the form you want to open.

Code: Select all   Expand viewCollapse view
Sub onClickOpenForm ( oEvent as variant )
   OpenForm(oEvent, "My Form Name")
End sub

Using this method you can set up additional functions for all of your forms. For example if you have a form called "Index Form", you could have the method:

Code: Select all   Expand viewCollapse view
Sub onClickOpenIndexForm ( oEvent as variant )
   OpenForm(oEvent, "Index Form")
End sub

The final step is then to assign the new "onClickOpen..." function to the appropriate button on your form, although I tend to use the "When Initiating" event for the button rather than the "Mouse button released" event
Posts: 11
Joined: Sun Feb 03, 2008 12:37 pm

Return to Base

Who is online

Users browsing this forum: No registered users and 7 guests