Custom Menus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a 2002 format project. I have built a custom menu for the app. In
the On Action I've put
DisplayFormA

in a module
Public Function DisplayFormA()
forms!FormA.setfocus
forms!FormA.textbox_a.setfocus
(other stuff)
end Function

When the menu item is selected it executes the function 3 times, always
three times. Why? this is driving me crazy. I've looked everywhere and
can't find a reason.

Any help would be appreciated.
 
try this:
Function openform(Formname,textboxname as string)
docmd.openform formname
textboxname.setfocus
end function

on menu action put this:
openform("FormA","textbox_a")
 
The running 3 times is known problem, but it usually ONLY occurs when you
qualify the function name with a full forms path name.

You mention you put the code in a module, are you talking about a standard
module, or the forms module?

If you put the code in the forms module, then you need to go for the on
action as:

=DisplayFormA()

If you go

=Forms!MyCoolForm.DisplayFormA()
Then the code will run 3 times. So, don't qualify the forms ref, and you
should be ok.

As mentioned, you can put the code in a standard module, or even in the
forms module (you still must declare the function as public). Since the code
belongs with the particular form, then likely you should put the code in the
actual form...but as mentioned, do NOT qualify the function with the
particular forms name...and it will NOT run 3 times. (another work around is
to move the code to a standard module..and again it will not run 3 times).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top