PC Review


Reply
Thread Tools Rate Thread

Calling Procedure from OnAction

 
 
Pete G
Guest
Posts: n/a
 
      9th Sep 2008
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


 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Sep 2008
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
>
>



 
Reply With Quote
 
Pete G
Guest
Posts: n/a
 
      9th Sep 2008
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
> >
> >

>
>
>

 
Reply With Quote
 
Pete G
Guest
Posts: n/a
 
      10th Sep 2008
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
> > >
> > >

> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.OnAction points to wrong file.module.procedure =?Utf-8?B?RGF0YXNvcnQ=?= Microsoft Excel Programming 1 1st Oct 2005 12:43 AM
OnAction procedure Max Potters Microsoft Excel Programming 4 26th Sep 2004 07:58 PM
VBE Custom menuitem not calling OnAction macro R Avery Microsoft Excel Programming 5 13th Jul 2004 10:39 PM
Calling a Procedure Ashish Nanda Microsoft Access Database Table Design 0 2nd Sep 2003 10:29 PM
Re: Calling a procedure Jon Cosby Microsoft ADO .NET 0 11th Aug 2003 05:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:22 PM.