Access module

R

Ryan

How do I run a module from a query and pass the variables
from the module to the Query?

thanks, Ryan
 
W

Wayne Morgan

You don't run a "module". The way to do what you are asking is to create a Public Function
in the module and call it as you would a built-in function. Don't use the name of any
module as the name of any function or sub.

Example:
Public Function MyTest(intNumber As Integer) As Integer
MyTest = intNumber +1
End Function

In the query, create a calculated field or you could use the function in the criteria,
depending on what you are trying to do.

Example Field value for a calculate field.

Expr1: MyTest(Nz([Table1].[Field1],0))

This will give you a field in the query's output called Expr1. The value of this field
will be 1 more than the value of [Table1].[Field1]. The Nz function will replace a Null
value in Field1 with 0.
 
T

Tom Ellison

Dear Ryan:

I'd like to suggest some terminology changes, assuming I've understood
you correctly.

A module is a collection of subroutines and functions (along with
declarations). You do not "run" a module, but you can "call" a
function or subroutine that is in the module. Saying "run" instead of
"call" would be quite clear, too.

If you're calling / running / invoking a function that is in a module
you do so just like you would from inside VBA:

FunctionName (Parameter1, Parameter2, . . .)

These Parameters can be constants, other functions, or columns in the
tables or queries included in the query containing the function. The
value returned by the function will appear as though it were replacing
the function call.

Keep in mind that the function in your module must be Public.

Is that what you were wanting to know?

How do I run a module from a query and pass the variables
from the module to the Query?

thanks, Ryan

Tom Ellison
Ellison Enterprises - Your One Stop IT Experts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top