Compiler miscounting parameters in a private function

  • Thread starter Thread starter paul.schrum
  • Start date Start date
P

paul.schrum

Access 2002

Can someone help me fix this problem?

In a form module I have a

Private Sub addReplacementKey(key_chain_id As Long, unique_id As Long)

The compiler does not seem to realize that the sub has two parameters.
When I call the sub (from code behind a button) as

addReplacementKey (key_chain_id, unique_id)

the compiler colors it red. When I call the function as

addReplacementKey (key_chain_id)

it compiles okay. Not only do I not understand why it is doing this,
but, more importantly, what should I do about it?

- Paul Schrum
 
Access 2002

Can someone help me fix this problem?

In a form module I have a

Private Sub addReplacementKey(key_chain_id As Long, unique_id As Long)

The compiler does not seem to realize that the sub has two parameters.
When I call the sub (from code behind a button) as

addReplacementKey (key_chain_id, unique_id)

the compiler colors it red. When I call the function as

addReplacementKey (key_chain_id)

it compiles okay. Not only do I not understand why it is doing this,
but, more importantly, what should I do about it?

Try removing the blank before the left parenthesis. It may also be
necessary to recompile the project (if you haven't done so already),
or perhaps even to Decompile and recompile it.

John W. Vinson[MVP]
 
To invoke a subroutine, you need to either leave the parameters out of
parentheses, or use the Call keyword:

addReplacementKey key_chain_id, unique_id

or

Call addReplacementKey (key_chain_id, unique_id)

It's a fluke that it works with a single parameter: IIRC, putting a single
parameter in parentheses changes the meaning from ByVal to ByArg (or vice
versa)
 
Would I find these in help? (I haven't checked yet.) In other words,
how do I do either of those.

- Paul

Sounds like Douglas has the right answer (and I learned something
tonight, thanks Douglas!)

To compile, open the VBA editor and select Debug... Compile <database
name> from the menu. I would recommend doing this EVERY SINGLE TIME
you edit code, before attempting to run it.

To decompile you need to use the only-recently documented /decompile
runtime switch:

http://support.microsoft.com/default.aspx?scid=kb;en-us;819780

John W. Vinson[MVP]
 
John (and also, attn Douglas Steel),

I took three measures:

I decompiled then compiled.
I changed the line calling the sub to have the "call" keyword.
And I changed the name of the sub (it needed a better name anyway).

After doing all of those things the problem resolved. So thanks to
both of you. Somewhere in all of that the problem got fixed.

- Paul Schrum
 
It was the second thing. The other two won't have hurt, but you were calling
the sub incorrectly.
 
Back
Top