Customize Menu button - if code


I have customized the menu.
I have an icon that if pressed opens a checklist
I need to have code on the click event of this button to open a different checklist if a condition is true but do not know if this is possible?

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Your Menu Button will need to point to a Macro.  That macro can either use Conditions, or just run straight to VBA and check conditions there, your choice!

Let me know if you need more.
PetrobrasAuthor Commented:
sweekes283, thanks for the response.   I would need for it to go to VBA but not sure how to do this.  Can you run through steps to allow me to enter code like I would as if I were on a click event of a button?

First thing, build your VBA Function (has to be a public function).  Have it set up so that it opens the checklist exactly as you need it to, so all you have to do is run it and it'll work (no passing variables or anything).

Then, build a macro in the macro editor.  It'll have only one action, RunCode and you'll enter the name of your function in the parameter box.

Lastly, customize your menu and add the macro as your button (it'll be in All Macros).

If you need more, post the VBA or more details and I'll explain.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

PetrobrasAuthor Commented:
sweekes, I say that it needs to be code only because I do not know how a macro could duplicate what i am doing by code but maybe a macro would be easier.  I am not a programmer but know a small amount.  

I want you to inspect the code and tell me if a macro or code would be easier.
If I was to write a function I am not exactly sure what the first line opener would look like.
eg Public Function statement

Private Sub Check_List_Click()

     If Forms!frmDeals!ProgramType = "Short Term" And Forms!frmDeals!InsuranceOrGuarantee = "Bridge" Then
        DoCmd.OpenForm "frmCheckListBridge"
    ElseIf Forms!frmDeals!ProgramType = "Short Term" And Not Forms!frmDeals!InsuranceOrGuarantee = "Bridge" Then
       DoCmd.OpenForm "frmCheckListST"
        DoCmd.OpenForm "frmCheckList"
   End If

End Sub

You still need the code, but you need a way of triggering the code.  A macro can call the function from the menu.  If you know of a way to call code from a toolbar/menubar without using some other object (hidden form or macro) then go for it.

The macro only needs one action, RunCode: Check_List_Click()

You'll have to change it to a public function but that's it.
Oh, and to make that Private Sub a Public Function you just change that:

Public Function Check_List_Click()

End Function
Leigh PurvisDatabase DeveloperCommented:
You can call a function directly too of course - bypassing the more flighty macro
Setting the OnAction property of the menu/toolbar button to
Leigh PurvisDatabase DeveloperCommented:
(As sweekes mentions - it must be a *public* function of course).
PetrobrasAuthor Commented:
the code is presently found in a form.
Are you saying to just simply change the Private to Public and leave the code in the form?
I was thinking that I would have to put the Public in a module.
Then call it and it will work.

One way to find out... Try it!

I know for a fact it will work in a module.  I don't mess around too much with menubars, so if it's as easy as LPurvis is saying, go for that instead.

And I believe you may still need to change it to a Function, but again, try it as a public sub and see if it works...
Leigh PurvisDatabase DeveloperCommented:
You're right in that thinking. :-)

You can reference a form and it's code - but it is not nice and is prone to failure and/or results you don't want.
A public function in a standard module can be fully error handled to deal with the form being open or not and so forth.
PetrobrasAuthor Commented:
ahhh....worked like a charm.  Thanks kids!

might be a dumb question but I can't seem to figure out how to rename a module: module1 to a more descriptive name
it is an old module (not the one I just made).  It says Module1.

Leigh PurvisDatabase DeveloperCommented:
Select it in the db window.
Click on it again - or hit F2

PetrobrasAuthor Commented:
forgot about the double click.  
I right click on most everything then rename or hit f2

Thanks for the split Petrobras!

Have a happy new year!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.