Adding a Button To Open Another Form

From NeoWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:27, 5 October 2007 (edit)
Lorinda (Talk | contribs)
m (Create The Necessary Macros - set code in preBox; other formatting changes)
← Previous diff
Revision as of 01:50, 5 October 2007 (edit) (undo)
Lorinda (Talk | contribs)
(Create The Necessary Macros - correct process so macro is saved with the document.)
Next diff →
Line 6: Line 6:
Note: The macros below were found in [http://www.oooforum.org/forum/viewtopic.phtml?p=152098#152098 This thread of the oooforums.org Base forum.] The only changes involve changing the form names. Note: The macros below were found in [http://www.oooforum.org/forum/viewtopic.phtml?p=152098#152098 This thread of the oooforums.org Base forum.] The only changes involve changing the form names.
 +# In the main database document window, click on {{prefName|Forms}} in the left hand column.
 +# Control-click or right-click on the '''Field Trips Data Entry''' form and choose {{Menu|Edit}} from the contextual menu. The form will open.
# Under the {{Menu|Tools}} menu, choose {{Menu|Macros}}, then {{Menu|Organize Macros}} and finally {{Menu|NeoOffice Basic}} # Under the {{Menu|Tools}} menu, choose {{Menu|Macros}}, then {{Menu|Organize Macros}} and finally {{Menu|NeoOffice Basic}}
# Click the {{Button|Organizer}} button # Click the {{Button|Organizer}} button
-# In the {{Window|NeoOffice Basic Macro Organizer}} window, click on the {{Section|Libraries}} tab+# Click on the flipply triangle to the left of the document icon named {{prefName|Field Trips Data Entry}}
-# Click the {{Button|New}} button+# Click on the folder icon named {{prefName|Standard}} that appears
-# Give the new library a name. I chose "DatabaseMacros" (without the quotes)+# Click the {{Button|New}} button; the {{Window|New Module}} window appears.
 +# Give the new module a name. I chose "ButtonMacros" (without the quotes)
# Click {{Button|OK}} # Click {{Button|OK}}
-# Click {{Menu|Close}} in the {{Window|NeoOffice Basic Macro Organizer}}+# A new window will open, titled {{Window|Field Trips Data Entry.Standard - Basic}}. You will see the following lines:
-# In the {{Window|NeoOffice Basic Macros}} window, click on {{prefName|My Macros}}+
-# Now click on the flippy triangle next to the folder icon with the name you gave your library e.g. '''DatabaseMacros'''+
-# When the triangle "opens" the library, you will see {{prefName|Module1}} Click on it+
-# In the {{Section|Existing Macros in Module1}} section, you will see the word "Main"; select it+
-# Click on the {{Button|Edit}} button+
-# A new window will open. You will see the following lines:+
#::Sub Main #::Sub Main
#::End Sub #::End Sub
Line 51: Line 48:
# Click on the {{Button|Save}} button on the toolbar (it looks like a external "floppy" drive) # Click on the {{Button|Save}} button on the toolbar (it looks like a external "floppy" drive)
# Close the {{Window|My Macros & Dialogs}} window by clicking on the red circle in the upper left hand corner. # Close the {{Window|My Macros & Dialogs}} window by clicking on the red circle in the upper left hand corner.
 +''--> Note: This tutorial has you save this macro in the document. It is possible to save it to a module in "My Macros." But if you copy or move the document to another computer (or another user account), the form will be unable to find the macro that way. Saving the macro in the document insures that it will always be available to the form.''

Revision as of 01:50, 5 October 2007

This article is part of the To Base and Back Again tutorial series.

If you attempt to add a new field trip involving a location not already in the Locations table, you will encounter an error message. New locations must be added before the field trip data is entered. Because the Field Trips data entry form will be used most often, and because it is likely that users will forget to enter new locations first, we can make the user's experience easier by adding a button to the Field Trips Data Entry form that will open the Locations Data Entry form. This article explains how to do that.

Create The Necessary Macros

Note: The macros below were found in This thread of the oooforums.org Base forum. The only changes involve changing the form names.

  1. In the main database document window, click on Forms in the left hand column.
  2. Control-click or right-click on the Field Trips Data Entry form and choose Edit from the contextual menu. The form will open.
  3. Under the Tools menu, choose Macros, then Organize Macros and finally NeoOffice Basic
  4. Click the Organizer button
  5. Click on the flipply triangle to the left of the document icon named Field Trips Data Entry
  6. Click on the folder icon named Standard that appears
  7. Click the New button; the New Module window appears.
  8. Give the new module a name. I chose "ButtonMacros" (without the quotes)
  9. Click OK
  10. A new window will open, titled Field Trips Data Entry.Standard - Basic. You will see the following lines:
    Sub Main
    End Sub
  11. Click in the blank space after the "End Sub" line
  12. Enter the following 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()) end function function getFormsTC() as variant getFormsTC = thisComponent.Parent.getFormDocuments end function function getConnectionTC() as variant getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection end function REM Macro to open specific form called 'Locations Data Entry'. One is needed for each form you wish to open from another form. sub OpenForm_Locations_Data_Entry( oev as variant ) sFormName = "Locations Data Entry" OpenForm( getFormsTC, getConnectionTC, sFormName ) end sub
    --> Note: code under REM Generic macros needed to open any form only needs to be entered once in the Module. If you add buttons to open other forms later, all you need to do is copy the code under REM Macro to open specific form and change the names in the first two lines to reflect the form you want opened. In the first line (that begins sub OpenForm_), you cannot use spaces in naming the macro; you must use underscores instead.
  13. Click on the Save button on the toolbar (it looks like a external "floppy" drive)
  14. Close the My Macros & Dialogs window by clicking on the red circle in the upper left hand corner.

--> Note: This tutorial has you save this macro in the document. It is possible to save it to a module in "My Macros." But if you copy or move the document to another computer (or another user account), the form will be unable to find the macro that way. Saving the macro in the document insures that it will always be available to the form.

Personal tools