a dumb question

G

Guest

How do I run sub() from with the code of a command button on a form?
the procedure I want to run as called File_Clean()
I can use this to run a macro, but can't figure out how to run a sub() in a
module.
DoCmd.RunMacro stDocName
thanks,
ck
 
D

Dirk Goldgar

In
Charlie said:
How do I run sub() from with the code of a command button on a form?
the procedure I want to run as called File_Clean()
I can use this to run a macro, but can't figure out how to run a
sub() in a module.
DoCmd.RunMacro stDocName

Either just write the sub's name in your code, or use the Call statement
to explicitly call it. Like this:

'----- start of example code -----
Private Sub MyButton_Click()

' you can do this:

File_Clean

' or this:

Call File_Clean

End Sub
'----- end of example code -----
 
G

Guest

Is there a reason (performance?) for using the Call statement as opposed to
just writing the sub's name?
 
K

Klatuu

I don't know that there is a performance difference, but for readablilty, I
prefer the Call. It is obvious to the read what is happening.
 
D

Dirk Goldgar

In
pjgalloway said:
Is there a reason (performance?) for using the Call statement as
opposed to just writing the sub's name?

No technical or performance reason I'm aware of. As far as I know, it's
just a matter of personal preference. Some people like to use the Call
statement to make it clear that a subroutine is being called. I prefer
to write subroutines with meaningful names that state what they're
supposed to do, and just write the name alone. If I have to call some
procedure without a descriptive name -- for example, if I have to call
an event procedure -- then I use the Call statement.

Since I work in a one-programmer shop, that style works well for me.
Companies that have multiple software developers working on the same
project might find otherwise -- or not -- and ought to establish a style
guideline that enforces some consistency.
 
M

missinglinq via AccessMonster.com

The Call statement is for oldtimes like mysel, I think! Used to be you had to
use and they left it in for backwards compatibilty! BTW, how you pass
arguments depends on how you invoke the sub:

Call HouseCalc(380950, 49500)

or

HouseCalc 380950, 49500

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

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

Top