VBA Code

G

Garry

I am very confused!!
I am working on an application that includes public subs in a module. An
example is:
Public Sub CancelCurOrder(NewOrderNo As Long)
When I use the sub in VBA code I have:
CancelCurOrder (NewOrder)

I recently added another public sub to the module:
Public Sub UpdateInventory(ItemNo As String, Delta As Integer)
When I try to use it in the VBA code as:
UpdateInventory(stDocName, iNum)
I get an error in the VBE stating “= expectedâ€

If I use it without the parentheses:
UpdateInventory stDocName, iNum
It works fine.

Can anyone explain what is going on??? When are parentheses required and
when not???
 
D

Douglas J. Steele

You got lucky in the first case!

Access allows it with a single parameter, but if you have multiple
parameters, it doesn't. Either don't use parentheses, or include the keyword
Call in front:

UpdateInventory stDocName, iNum

or

Call UpdateInventory(stDocName, iNum)
 
6

'69 Camaro

Hi, Garry.
When I try to use it in the VBA code as:
UpdateInventory(stDocName, iNum)
I get an error in the VBE stating “= expectedâ€

That's because you're using the syntax for a function that returns a value,
not the syntax for a subroutine. Instead, try:

Call UpdateInventory(stDocName, iNum)
Can anyone explain what is going on???

Ingeniously intuitive, isn't it? Microsoft, the inventor of VB, believes
so. You've discovered one of the thirteen reasons to loathe VB. Please see
the following Web page for a link to Verity Stob's expose on the subject,
"Thirteen Ways To Loathe VB":

http://www.Access.QBuilt.com/html/articles.html
When are parentheses required and
when not???

It depends. Are there formal parameters? If not, then no parentheses. Is
it a function or a subroutine with formal parameters? Again, it depends.
Use "Call" preceding the name of the subroutine when using parentheses around
the parameters and use the assignment operator "=" preceding the name of the
function when using parentheses around the parameters, and you'll be fine.
For example:

Call mySub(param1, param2)
a = sqrt(b)
Call myOtherSub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Top