Using functions of same name

  • Thread starter Thread starter Vince
  • Start date Start date
V

Vince

Is it possible to utilize a user-defined function in a query where the
function name exists in multiple modules?

I have setup 2 modules modEmployees and modDepartments. Each has a
recCount function that returns the number of rows in the tblEmployees
and tblDepartments tables respectively.

When I try to utilize either function in a query, I get an error of
"Ambiguous name". I can live with that. However, when I try to add
which module the function comes from ( i.e. modEmployees.recCount() ) I
get an "Undefined function 'modEmployees.recCount' in expression error.


Is there a way around this? I really dont want to rename the function
modEmployees.employeeRecCount as it does not fit into my naming
convensions. This is just an example, I realize that I can create a
single function which takes the name of the table and returns the
record count, but I just used this very simple example to illustrate
the issue.

Thanks.
 
Rename one of the functions and everything should go fine. Just be sure to
change the reference in the query where appropriate.
 
Thanks, but I already stated that. I am trying to find out if there is
an alternative.

So you'll spend lot's of time posting, and waste the time of those of
us who read your message, when you can simply change one of the
function's name from recCount() to recCountEmp()? Actually, you would
be well advised to change both names. recCountEmp() and
recCountDept() sound more descriptive to me, and will certainly be
easier for someone a year from now to follow what the code is trying
to do.
 
I am sorry that someone misunderstood my question, I guess I wasnt
direct enough in my wording.

I understand I CAN change the name of the function and the names used
in my example were the simplest example I could think of that readers
could quickly understand. The jist of my question is if those functions
can coexist happily within the VBA "module" world, why can't the
"Query" part of Access also understand the module.function convention?
What happens to the "module." part in Queries/Jet?
 
If you try to compile your code, I think you will find that they don't
co-exist very well. Since you are allowed to create two functions with the
same name, it would be nice if you could disambiguate the functions by
specifying the module name. In most cases, you can't.
 
Back
Top