No wonder I've been wondering around in the desert trying to figure this one
out.
In the example from Access VBA for "OnAction Property (Office):
[Help text states:] The procedure named "MySub" will run each time the
control is clicked. [The name alone sounds like a SUB, not a FUNCTION.]
Set myBar = CommandBars("Custom")
Set myControl = myBar.Controls _
.Add(Type:=msocontrolButton)
With myControl
.FaceId = 2
.OnAction = "MySub"
End With
myBar.Visible = True
Further, in the example from Access VBA for "Adding and Modifying Toolbars
(Office)" onAction is defined to call the SUB "changefaces."
Sub testAddModifyToolbars1()
Set myBar = CommandBars _
.Add(Name:="ChangingButton", Position:=msoBarTop, _
Temporary:=True)
myBar.Visible = True
Set oldControl = myBar.Controls _
.Add(Type:=msoControlButton, _
ID:=CommandBars("Standard").Controls("Copy").Id)
oldControl.OnAction = "changeFaces"
End Sub
Sub changeFaces()
Set newControl = CommandBars.FindControl _
(Type:=msoControlButton, _
ID:=CommandBars("Standard").Controls("Paste").Id)
newControl.CopyFace
Set oldControl = _
CommandBars("ChangingButton").Controls(1)
oldControl.PasteFace
End Sub
Not helpful.
Thanks, again.
Pete
"Pete G" wrote:
> And VOILA, it works. As you suggested, I simply renamed the SUB procedure as
> a FUNCTION procedure and everything is good. I've been programming in Excel
> VBA and am new to Access VBA. Haven't used functions at all. Everything as
> been a SUB so far.
>
> Thanks so much.
>
> Pete
>
> "Douglas J. Steele" wrote:
>
> > What do you mean by "a procedure"? If it's a Sub, it's not possible. If it's
> > a Function, use =FunctionName(Parm1, Parm2, ....)
> >
> > If the function is in a common module (as opposed to the class module
> > associated with the form), it must be Public, not Private.
> >
> > Note that if you do have a sub, you can simply change it to a function: it
> > doesn't actually have to return anything.
> >
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no private e-mails, please)
> >
> >
> > "Pete G" <Pete (E-Mail Removed)> wrote in message
> > news:2C2EE785-98FE-4590-A86C-(E-Mail Removed)...
> > >I have created a popup menu that shows when I click a text box in my form.
> > > The menu works great. I can put code in the onAction property that will
> > > actually work. For example if I manually enter "=MsgBox("Wow")" (without
> > > quotes around the outside or if I use code in VBA to fill in the OnAction
> > > property:
> > > .OnAction = "=MsgBox(""Wow!"")"
> > > everything works fine.
> > >
> > > What I want to do is call a procedure from onAction.
> > >
> > > I have found numerous examples online that state if I simply type a
> > > procedure name in onAction, the button click nf the menu item will run my
> > > procedure.
> > >
> > > No luck doing that. Nothing happens. No errors, nothing.
> > >
> > > I know my procedure works because if I set up a textbox and put my
> > > procedure
> > > in the click event for the button all is well.
> > >
> > > I'm sure I'm missing something very simple here. My sense is that Access
> > > can't find my procedure or some syntax in OnAction isn't quite right.
> > >
> > > Any help?
> > >
> > > Thanks,
> > > Pete
> > >
> > >
> >
> >
> >