Connecting Tech Pros Worldwide Forums | Help | Site Map

User Defined Functions in Queries.

Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#1: Feb 26 '07
I know I can use my own functions with DoCmd.RunSQL but can this also be done in queries?

I've tried using a Public Function in normal module but it doesn't work. Is there another way to do it?

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#2: Feb 27 '07

re: User Defined Functions in Queries.


Quote:

Originally Posted by Rabbit

I know I can use my own functions with DoCmd.RunSQL but can this also be done in queries?

I've tried using a Public Function in normal module but it doesn't work. Is there another way to do it?

I can't remember which it is but I think you can use your own defined public functions in the select criteria but not in the where criteria.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#3: Feb 27 '07

re: User Defined Functions in Queries.


I just tried it and it works in the Where criteria if you're only returning a string. Otherwise you'll have to modify the QueryDef from outside the query.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#4: Feb 27 '07

re: User Defined Functions in Queries.


Nice work Rabbit - 400 posts as I type :)
As far as the UDFs go I find that they are fully accessible in queries as long as they are defined as Public in a standard module. Most can be accessed ok from a form or report module too if the form/report is open and you know how to reference it properly. Standard modules are a lot simpler mind.
Reply