Connecting Tech Pros Worldwide Help | Site Map

Sub won't accept parentheses around arguments

Lyn
Guest
 
Posts: n/a
#1: May 28 '07
Can anyone explain this for me?

A sub procedure can be called with or without parentheses around the
arguments. By personal convention, I normally use parentheses. I am in
the middle of a fairly large project (for me), happily using parentheses
everywhere -- until this happened:

The following sub is defined in a class module.

Public Sub DeleteXXRecord(lngEORekNombro As Long, lngXXRekNombro As Long)
[..code..]
End Sub

In another (form) module, I call the sub thus:

Dim A As Long
Dim B As Long

A = [some long number]
B = [some long number]

DeleteXXRecord(A, B)

While typing this last line, Intellisense seems to be quite happy with what
I am typing. But as soon as I newline after entering the line, it turns
red. Doing a compile gives me "Syntax error" on this line.

I have been agonizing over what could be wrong with such a simple sub call,
trying to cut down the code to the bare basics -- all to no avail. Until
in desperation I decided to try deleting the parentheses -- thus:

DeleteXXRecord A, B

Lo and behold, this actually compiled error-free. The only sub call in the
whole project without parentheses!

I know that many people don't use use parentheses with sub calls. I do it
mainly for consistency with function calls (I've gotten into the habit).
As far as I know, parentheses around a sub's arguments should always work.

Have I got this wrong somehow???

Thanks for any help,
Lyn.
UrbanSpaceman
Guest
 
Posts: n/a
#2: May 28 '07

re: Sub won't accept parentheses around arguments


All you need in order to keep using parens is to 'call' the sub:

Call DeleteXXRecord(A, B)

"Lyn" <l.hancock@iiNet.net.auwrote in message
news:t2orusctal4l$.1xove5w6shju1.dlg@40tude.net...
Quote:
Can anyone explain this for me?
>
A sub procedure can be called with or without parentheses around the
arguments. By personal convention, I normally use parentheses. I am in
the middle of a fairly large project (for me), happily using parentheses
everywhere -- until this happened:
>
The following sub is defined in a class module.
>
Public Sub DeleteXXRecord(lngEORekNombro As Long, lngXXRekNombro As Long)
[..code..]
End Sub
>
In another (form) module, I call the sub thus:
>
Dim A As Long
Dim B As Long
>
A = [some long number]
B = [some long number]
>
DeleteXXRecord(A, B)
>
While typing this last line, Intellisense seems to be quite happy with
what
I am typing. But as soon as I newline after entering the line, it turns
red. Doing a compile gives me "Syntax error" on this line.
>
I have been agonizing over what could be wrong with such a simple sub
call,
trying to cut down the code to the bare basics -- all to no avail. Until
in desperation I decided to try deleting the parentheses -- thus:
>
DeleteXXRecord A, B
>
Lo and behold, this actually compiled error-free. The only sub call in
the
whole project without parentheses!
>
I know that many people don't use use parentheses with sub calls. I do it
mainly for consistency with function calls (I've gotten into the habit).
As far as I know, parentheses around a sub's arguments should always work.
>
Have I got this wrong somehow???
>
Thanks for any help,
Lyn.

missinglinq via AccessMonster.com
Guest
 
Posts: n/a
#3: May 28 '07

re: Sub won't accept parentheses around arguments


In other words you can invoke a sub in two different ways

Call DeleteXXRecord(A, B)

or

DeleteXXRecord A, B

but you can't mix and match i.e.

DeleteXXRecord(A, B) or Call DeleteXXRecord A, B

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

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1

Lyn
Guest
 
Posts: n/a
#4: May 29 '07

re: Sub won't accept parentheses around arguments


On Mon, 28 May 2007 14:34:53 GMT, missinglinq via AccessMonster.com wrote:
Quote:
In other words you can invoke a sub in two different ways
>
Call DeleteXXRecord(A, B)
>
or
>
DeleteXXRecord A, B
>
but you can't mix and match i.e.
>
DeleteXXRecord(A, B) or Call DeleteXXRecord A, B
Thanks to both who responded. I have researched the Call statement which
confirms what you have said. I have also now tried:

Call DeleteXXRecord (A, B)

and it works as advertised.

It is strange that in three years of using the parentheses format without
the "Call" statement, it has always worked perfectly -- up until now. VBA
must be loose enough to allow this erroneous syntax in most cases.

However, the writing is on the wall -- I am going to have to change my
style of calling Subs!

Thanks for the help!

Lyn.
Closed Thread