By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

Really stupid N00b question

P: n/a
When you use a function like I see posted here often, like:

Public Function Whatever()
stuff...
End Function

What do you actually do with that to make it run? I assumed you put it in a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

Maybe someone can show me where to start reading on using funcitons? I start
looking through the help files but quickly get overwhelmed. Seems like
almost all subjects start past the point of square 1, like you're already
supposed to know a bunch of things before help topics even get going.

May 1 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
You can type Whatever() in the inmediate window (CTR+G) to see what it
does, or run it in any procedure in your project, again just by typing
its name

May 1 '06 #2

P: n/a
There are various ways to make your public functions run;
From the Immediate window to make the example functionrun, type the following and press enter;

?whatever

To get it to run from an event, within the VBA window of the
form/report you could put the following in the chosen event;

Call Whatever

The function is run when the event is fired.

I'm sure there are others who can explain this more elegantly and
expand on your question.

Hope this helps though.

Cheers

Phil

Alan wrote: When you use a function like I see posted here often, like:

Public Function Whatever()
stuff...
End Function

What do you actually do with that to make it run? I assumed you put it in a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

Maybe someone can show me where to start reading on using funcitons? I start
looking through the help files but quickly get overwhelmed. Seems like
almost all subjects start past the point of square 1, like you're already
supposed to know a bunch of things before help topics even get going.


May 1 '06 #3

P: n/a
Hi, Alan.
What do you actually do with that to make it run? I assumed you put it in
a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.
If it's a function or subroutine that doesn't accept any parameters, then
you can test it by placing your curson on the first line of the procedure:

Public Function Whatever() As String

.. . . and then hit the Run button (or hit <F5> or use the Run -> Run
Sub/UserForm menu), to run the procedure. If the procedure accepts
parameters, then you'll have to call this procedure from another. For
example:

Public Sub testingWhatever()
Dim myVariable As String
myVariable = "today"
MsgBox Whatever(myVariable)
End Sub

.. . . and just place the cursor on the first line of testingWhatever() and
then hit Run to find out what "today" brings you.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"Alan" <Al********@msn.com> wrote in message
news:97*******************@216.196.97.136... When you use a function like I see posted here often, like:

Public Function Whatever()
stuff...
End Function

What do you actually do with that to make it run? I assumed you put it in
a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

Maybe someone can show me where to start reading on using funcitons? I
start
looking through the help files but quickly get overwhelmed. Seems like
almost all subjects start past the point of square 1, like you're already
supposed to know a bunch of things before help topics even get going.

May 1 '06 #4

P: n/a
"Alan" <Al********@msn.com> wrote in message
news:97*******************@216.196.97.136...

What do you actually do with that to make it run? I assumed you put it in
a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

If the cursor is not within a procedure, VBA does not know what procedure to
run, so it gives you the popup to select from.

John... Visio MVP
May 2 '06 #5

P: n/a
Hi, John.

Even if the cursor is within a procedure when the Run button is hit, the
popup asking for a macro name can still show up. It happens with class
modules and with procedures that require parameters.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"John Marshall, MVP" <la******@stonehenge.ca> wrote in message
news:35********************@magma.ca...
"Alan" <Al********@msn.com> wrote in message
news:97*******************@216.196.97.136...

What do you actually do with that to make it run? I assumed you put it
in a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

If the cursor is not within a procedure, VBA does not know what procedure
to run, so it gives you the popup to select from.

John... Visio MVP

May 2 '06 #6

P: n/a
True. I was trying to explain why the popup was there without going into too
much details on the exceptions. The cursor can be within a procedure that
does not have parameters, but if the window does not have focus, VBA will
give the popup.

John... Visio MVP
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote in
message news:w-******************************@adelphia.com...
Hi, John.

Even if the cursor is within a procedure when the Run button is hit, the
popup asking for a macro name can still show up. It happens with class
modules and with procedures that require parameters.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"John Marshall, MVP" <la******@stonehenge.ca> wrote in message
news:35********************@magma.ca...
"Alan" <Al********@msn.com> wrote in message
news:97*******************@216.196.97.136...

What do you actually do with that to make it run? I assumed you put it
in a
module. If I do that and hit the run sub/user form button I get a popup
asking me for a Macro Name. I'm not sure what to do from here.

If the cursor is not within a procedure, VBA does not know what procedure
to run, so it gives you the popup to select from.

John... Visio MVP


May 2 '06 #7

P: n/a
Hi, John.

I learn something new every day. Thanks for testing that. It would never
occur to me to run a procedure from the VB Editor during testing that I
wasn't currently looking at.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"John Marshall, MVP" <la******@stonehenge.ca> wrote in message
news:3r******************************@magma.ca...
True. I was trying to explain why the popup was there without going into
too much details on the exceptions. The cursor can be within a procedure
that does not have parameters, but if the window does not have focus, VBA
will give the popup.

John... Visio MVP
"'69 Camaro" <Fo**************************@Spameater.orgZERO_SP AM> wrote
in message news:w-******************************@adelphia.com...
Hi, John.

Even if the cursor is within a procedure when the Run button is hit, the
popup asking for a macro name can still show up. It happens with class
modules and with procedures that require parameters.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
"John Marshall, MVP" <la******@stonehenge.ca> wrote in message
news:35********************@magma.ca...
"Alan" <Al********@msn.com> wrote in message
news:97*******************@216.196.97.136...

What do you actually do with that to make it run? I assumed you put it
in a
module. If I do that and hit the run sub/user form button I get a
popup
asking me for a Macro Name. I'm not sure what to do from here.
If the cursor is not within a procedure, VBA does not know what
procedure to run, so it gives you the popup to select from.

John... Visio MVP

May 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.