Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use OnAction to open form from menu bar

Status
Not open for further replies.

Schof

Programmer
Nov 18, 2002
103
CA
I would like to create a menu item that when clicked opens a form and passes some information in the openargs. The following works perfectly fine in VB:

DoCmd.openForm "My Form", , , , , , "My Args"

I have tried to add it to my menu item OnAction property as...

=DoCmd.openForm("My Form", , , , , , "My Args")

...but that does not work. Any ideas?
 
the gist is that you'll make make a macro with your code, then plunk that macro name into your OnAction of the menu item.

make a new macro sheet.
make a macro in it called i.e. GoToForm
the action is OpenForm, etc, with a where statement of your code above.
save the macro sheet as Menus. you can make more of them later if you need to.

in the OnAction of your menu item, choose the macro.

Another option is to make a module with a function in it called i.e. GoToForm with your code above in it.
then the macro GoToForm is instead RunCode and choose GoToForm below in the macro design. then, same as before, plunk the macro name into the OnAction of the menu item.

i have a module called Menus and a macro sheet called Menus where i put all this stuff. beauty of having the vb code in a function is that it can do more stuff than you can sometimes do in a macro alone.

g
 
Thanks GingerR, I was hoping to get away from having to do that but...do what you must. I tried your suggestion on creating a function (in a module) but get the error The expression you entered contains invalid syntax. Any ideas? Here is what I have...

OnAction: =doCmdOpenForm("My Form",,,,,, "My Args")


Public Function doCmdOpenForm(formName As String, Optional view As AcFormView = acNormal, _
Optional filterName, _
Optional whereCondition, _
Optional dataMode As AcFormOpenDataMode = acFormPropertySettings, _
Optional windowMode As AcWindowMode = acWindowNormal, _
Optional openArgs)

DoCmd.openForm formName, view, filterName, whereCondition, dataMode, windowMode, openArgs

End Function
 
Got an answer elsewhere...

=doCmdOpenForm("My Form", "My OpenArgs")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top