basic help calling a function

kessmiller

New member
Local time
Today, 13:32
Joined
Mar 21, 2011
Messages
8
I have a macro that runs several steps and then I want it to export a file to text using a spec. The specs no longer work in the macros so I wrote a module to do the export. I can't get the macro to call the module correctly. I've broken it down to just the one command in the macro calling the module, but I can't get it to work.

I'm a newbie on modules and functions and know whatever is wrong with this is painfully stupid, but I can't find it. I have another module that looks just like it as far as I can see and it works - this one doesn't.


Function mod_karla()
On Error GoTo mod_karla_Err
MsgBox "Module mod_karla() has run"

mod_karla_Exit:
Exit Function
mod_karla_Err:
MsgBox Error$
Resume mod_karla_Exit
End Function

I have macro RunModuleTest set up that just has the one command to run the module:

RunCode Function Name Mod_karla()

When I run it I get an error that says 'The expression you entered has a function name that Microsoft Access can't find.' The macro single step box shows Macro name as RunModuleTest, action name RunCode, Arguments mod_karla(),error number 2425.
 
Okay, a couple of points.

1. You don't run a module. You run PROCEDURES that exist WITHIN a module.

2. In order to run a procedure from the macro, it would need to be in a Standard Module and not in a form or report module.

3. The module name can NOT have the same name as the procedure(s) in the module(s).
 
Thanks Bob! Changing the name of the procedure fixed the issue. My other procedure that worked was actually named differently - one had a dash and the other an underline. I knew it was stupidly simple!

What is the difference between standard and report/form procedures?
 
Functions and subroutines in a module can be used from anywhere in the db (if it's public). Subs and functions in a form or report can only be used by that form or report.

A subroutine carries out specified commands. Functions can carry out commands, but a function will also return a result. So if you asked access what a subroutine equals, you would get an error. If you asked what a function equals, Access will have an answer.
 

Users who are viewing this thread

Back
Top Bottom