User-Defined Fx in Query not Working

B

BarryC

I have a user-defined function in a query. The function is defined in a
module. It is as follows:

Option Compare Database

Global uidUser As Double

Public Function UserSession() As Double

UserSession = uidUser

End Function

The query looks like this:

SELECT ShiftTable1.Week, Sum(ShiftTable1.AvgOfUtilization1) AS
SumOfAvgOfUtilization1 FROM ShiftTable1
WHERE (((ShiftTable1.UID)=UserSession()))
GROUP BY ShiftTable1.Week;

When executed, the query returns no rows, even though there are
matching rows in the queried table and the debug window shows that
uidUser and UserSession are populated with the correct value.

When the actual value of UserSession is copied from the debug window
and used in the query, the query correctly returns rows.

How do I fix this?
 
D

Douglas J. Steele

Exactly what datatype is UID in the table?

Double sounds like an unusual choice for an ID, since it's prone to
round-off errors that can result in apparently equal numbers not actually
being treated as equal.
 
B

BarryC

Douglas said:
Exactly what datatype is UID in the table?

Double sounds like an unusual choice for an ID, since it's prone to
round-off errors that can result in apparently equal numbers not actually
being treated as equal.

It is Double.

Do you suggest Long?

I wanted to use GUID, but that type is unavailable.
 

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