How does on Call a function?

  • Thread starter Thread starter OldManEd
  • Start date Start date
O

OldManEd

I have written a function in a module. I now want to test it. I have tried
simply typing in the function's name (with parameters) in the intermediate
window.

I get a compile error, 'expected variable or procedure'

What am I doing wrong?

OMEd
 
It depends on what your function is meant to do,

If it is some sort of calculation, try putting a sub in the same module with
something like this:

Sub TestMyFunction()

MsgBox MyFunction(TestNumber or whatever your parameters are)

End Sub

if that goes wrong, then comment out your error traps in your function and
see which line is going wrong. (it's best to leave out error traps until you
know that everything is working fine)


A function that, for instance, effects the way a report is printed. like the
PrintLines function, is run by typing
=PrintLines(Report, TotGroup)
next to where it says OnPrint in the Properties box of the report

The useful IsLoaded function would usually get used within a module of a
form or report where it would check if a particular form is open before
running the code.



Evi
 
This only works if your talking about a standard code module (not a forms,
or report module).

And, it only works if you talking about a NON class module.

and, it only works if the function is declared as public...

In the debug window, you should be albe just type in the function name

NameOfFucntion

If it has paramters, then go:

NameOfFunction "parm1"

If the function actually *returns* valeus, then go:

? NameOfFunction("parm1")
 
The function is designed to return a string by looping thru a recordset and
concating some field values. This function has the same name as the module.
Is that a problem? I think I just type its name in the immediate window
with a constant as the parameter. I don' remember using a '?'

I don't know the difference between a class module and a non class module. I
believe it is a standard code module; it is not a form or report, nor a form
module or report module. Again, I'm too inexperienced to know the difference
between a form and a form module but since I'm not using a form that can't
be the problem. As far as I can determine I have not declared it as public.
I am using 'Function (name as variant) as variant.' Is this where I insert
'public?'

OMEd
 
A function cannot have the same name as any module. A module cannot
have the same name as any function or sub.

Using
? FunctionName(Argument)
will PRINT in the immediate window what ever the function returns
(assuming that what is returned is printable as a character string).

If you opened a module through the database window then you have a
standard code module (99%+ guess).



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Back
Top