Using data from global variable in SQL statement

  • Thread starter Thread starter T.
  • Start date Start date
T

T.

Hello,

I have a global variable, gblnUserID, that is successfully being passed from
form to form. What I need to have happen is when a form ex) frmAddresses is
opened a combo box is populated with data from a simple SQL statement:

SELECT [tblCity].[CityName] FROM tblCity WHERE
[tblCity].[System]=gblnUserID;

The problem is that when the form loads it keeps asking me to enter in the
value of gblnUserID. Is there a special way that I need to reference the
variable in the SQL statement??

TIA,

T.
 
Create a function that returns the value of the constant, and use the
function in the query:

Public Function UserID() as Long
UserID = gblnUserID
End Function

SELECT [tblCity].[CityName] FROM tblCity WHERE
[tblCity].[System]=UserID();
 
Back
Top