User-Defined Function Doesn't Execute

B

BarryC

I have a user-defined function that I put in a VB module. During the
"Main Menu" form_load event, it fills a Global Variable (uidUser) with
a number that I use to keep track of individual user data in a
multi-user environment.
Here's the code:

Global uidUser As Integer

Public Function UserSession() As Integer

' Used in queries for reports.
UserSession = uidUser

End Function


I call this function in queries like this:
SELECT Prod.UID, Prod.Department, Prod.Pcs
From Prod
WHERE (((DailyProd_ByDeptDt.UID)=usersession()));

This is embedded in the Datasource for a report. The problem is that
the function either doesn't execute all the time or that it doesn't
return anything.
 
G

Guest

I don't know if the SQL you posted is the real one, or just something you
have typed, but in the Where condition you specified a different table name

SELECT Prod.UID, Prod.Department, Prod.Pcs
From Prod
WHERE (((DailyProd_ByDeptDt.UID)=usersession()));
=====================================
Try this
SELECT Prod.UID, Prod.Department, Prod.Pcs
From Prod
WHERE Prod.UID=usersession()
 
V

Van T. Dinh

1. Do you use Option Explicit in all Modules?

2. Where do you dim the Public Variable? In the CBF (Code-Behind-Form)
Module or a Standard Module?

3. Same question for the function UserSession().

3. Describe / post the code that you use to assign the value uidUser.

4. Have you tried to use Debug.Print or MsgBox just before you use the
function UserSession() to check what value is returned by the function.
 
J

John Nurick

Or modify your query so it only returns two or three records, and set a
breakpoint on this line

UserSession = uidUser

so you can see what's going on.
 

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