I have a recollection of the name of a button on a form being used to insert a variable into a macro so the button name can dictate which form is opened.
Does anyone recall any details about this please?
Thank you very much for your help.
The most appropriate property of any FormControl object to pass arguments to event handlers is, imo, .Tag
. Strangely it is named “Additional information” in the editing dialog, Tab General
. I would prefer the well established syntax for query strings as used in URL.
See demo: disask94585formControlPassArgumentsViaTag.ods (12.2 KB)
The .Name
property isn’t even assured unambiguous. Two controls can have the same name.
This isn’t specific enough to me.
The Tag property is made for this (“Additional information” in the properties dialog).
Python macros to open any embedded report or form. Works with forms and reports in subfolders too.
def Open_Report_Button(e):
'''specify the hierarical name in the button's "Additional info" field'''
sName = e.Source.Model.Tag
OpenEmbedded(e.Source, sName, True)
def Open_Form_Button(e):
'''specify the hierarical name in the button's "Additional info" field'''
sName = e.Source.Model.Tag
OpenEmbedded(e.Source, sName, False)
def OpenEmbedded(src, sHierachicalName, bReport):
odb = getDBDocument(src)
if bReport:
container = odb.ReportDocuments
else:
container = odb.FormDocuments
obj = container.getByHierarchicalName(sHierachicalName)
obj.open()
def getDBDocument(src):
oModel = src.getModel()
# a button's parent is always a form
oForm = oModel.getParent()
oActiveConnection = oForm.ActiveConnection
oDataSource = oActiveConnection.getParent()
return oDataSource.DatabaseDocument
g_exportedScripts = Open_Form_Button, Open_Report_Button
Thank you both for your thoughts on this. This looks too complicated for me so I will continue creating individual macros for buttons to run, rather than create a single macro that is fed a variable by the button.
sub push_button_click(ev)
sTag = ev.Source.Model.Tag
doSomething_With(sTag)
End sub
Sub push_button_click2(ev)
Msgbox "Label of button: " & ev.Source.Model.Label & Chr(10) & _
"Name of button: " & ev.Source.Model.Name
End Sub
Thank you @sokol92, just what I needed.
Sub push_button_open_form(ev)
DIM FmName AS STRING
FmName = ev.Source.Model.Name
ThisDatabaseDocument.FormDocuments.getByName(FmName).open
End Sub