Re: modules and passing variables
- From: ArielZusya <ArielZusya@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Dec 2007 14:11:01 -0800
Oh wow... I guess it really was that simple... so... why did it work without
the "Call" when it was just one variable being passed? is it just more
tollerant of my rookyisms? Thanks for the help!
"Stuart McCall" wrote:
"ArielZusya" <ArielZusya@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message.
news:FD4CD15F-E53B-4FE3-B6B3-F76D9E3A345C@xxxxxxxxxxxxxxxx
I've recently discovered the joy of modules (as apposed to embedded VBA
associated with each form). I'm only just beginning to understand the
full
richness of modules. For the most part I've discoverd that I can take
some
of my more simple yet repetative code and place it in a module. For
example,
Where I would before have a button that calls code that closes the current
form and opens a seperate form, I can place the code in a module and have
the
name of the module be called from the form but with the name of the new
form
passed to the module in parenthesis. So, if my CloseThisAndOpenThat
function
takes stDocName as a variable in the module it would have
Public Sub CloseThisAndOpenThat (stDocName As String)
and then in the code for the button on the form it would have
CloseThisAndOpenThat ("frmSecondForm")
All of that works fantastically. Trouble is I'd like to do something
similar but passing more variables. If, in my module I have something
like:
Public Sub CloseThisAndOpenThat (stDocName As String, _
stQueryText As String, lnOptSelection As Long)
and then try
CloseThisAndOpenThat("frmSecondForm", "where tblMain.Issue1 = 1", 2)
I get an "expected =" error. What am I doing wrong? Thanks for your
help!
Ariel
Either remove the parens from your call:
CloseThisAndOpenThat "frmSecondForm", "where tblMain.Issue1 = 1", 2
or use the Call keyword:
Call CloseThisAndOpenThat("frmSecondForm", "where tblMain.Issue1 = 1", 2)
Incidentally, you don't need the parens here either:
CloseThisAndOpenThat ("frmSecondForm")
But the reason that code executed ok is because of the space character that
precedes the 1st paren.
So there are 3 calling methods for you. The choice is yours, whatever suits
your coding style. Just be sure to make your calls consistent, ie call all
sub procedures the same way. Less confusion for you and perhaps others
further down the road.
- Follow-Ups:
- Re: modules and passing variables
- From: Stuart McCall
- Re: modules and passing variables
- References:
- Re: modules and passing variables
- From: Stuart McCall
- Re: modules and passing variables
- Prev by Date: from access using automation run excel macro
- Next by Date: Re: modules and passing variables
- Previous by thread: Re: modules and passing variables
- Next by thread: Re: modules and passing variables
- Index(es):
Relevant Pages
|