User function in a query?

  • Thread starter Thread starter Gary Schuldt
  • Start date Start date
G

Gary Schuldt

Can I use a function I've written in the "criteria" of a Select query or the
"Update to" of an Update query?

I have a select query where I'm using fncX as a selection criterion and I
get a "Type mismatch" error.

Am I making an obvious mistake, or do you need more info about what I'm
doing?

Thanks!

Gary
 
So long as the function has been declared as public and it's in a regular
module, yes, you should be able to use your own function in a query. Does
your function properly handle the data type that you are sending to it? Look
at what you've declared the format to be for each of the function's
arguments, and verify that the field that is being used in the argument when
you call the function matches.
 
Ken,

It's an null-argument function. It just returns the value of a global
string variable.

One question: The table field is Text; what is the corresponding VBA
variable type?

I haven't been able to find a list of correspondences between Table field
type and VBA variable type anywhere. You know of one?

Thanks.

Gary
 
You'll need to post the function code and an example of how you're using it
in the query.

Not sure what you mean by a correspondence list. Number formats match up to
their corresponding numeric variables based on the Field Size value for the
field. Text fields match up to string variables. Autonumber fields match up
to Long variables. Date/Time fields match up to date variables. All will
match up to variant variables.
 
Back
Top