471,119 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Sub won't accept parentheses around arguments

Lyn
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.
May 28 '07 #1
3 2452
All you need in order to keep using parens is to 'call' the sub:

Call DeleteXXRecord(A, B)

"Lyn" <l.*******@iiNet.net.auwrote in message
news:t2*****************************@40tude.net...
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.

May 28 '07 #2
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

May 28 '07 #3
Lyn
On Mon, 28 May 2007 14:34:53 GMT, missinglinq via AccessMonster.com wrote:
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.
May 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

47 posts views Thread by Will Stuyvesant | last post: by
4 posts views Thread by Steve | last post: by
7 posts views Thread by vlsidesign | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.