Solved DLookup Statement Problem

Pac-Man

Active member
Local time
Tomorrow, 00:17
Joined
Apr 14, 2020
Messages
438
Hello,

Please help me. What is wrong with these statements. Every time it gives type mismatch error. In tblUser, Username is a short text field and lngUserID is a public variable defined as long integer.
Code:
Dim strUserName As String
strUserName = Nz(DLookup("UserName", "tblUser", "UserID ='" & lngUserID & "'"), "Untitled")
 
If UserID is a number field, don't use apostrophe delimiters.
 
If UserID is a number field, don't use apostrophe delimiters.
I tried this:
Code:
Dim strUserName As String
Me.txtUserNameWelcome = lngUserID
strUserName = Nz(DLookup("UserName", "tblUser", "UserID = lngUserID"), "Untitled")

and it gives me new error i.e. The expression you have entered as a query parameter produced this error: 'lngUserID'

To check value of lngUserID I used Me.txtUserNameWelocme = lngUserID to check if correct value is stored in the lngUserID in break mode and running line by line code using F8 key. Correct value is stored in the variable. When I used the same numerical value in DLookup, it works and when I use global variable lngUserID, it don't even though lngUserID contains the same numerical value. lngUserID is dimensioned as long.
 
Try
Code:
strUserName = Nz(DLookup("UserName", "tblUser", "UserID = " & lngUserID), "Untitled")
 

Users who are viewing this thread

Back
Top Bottom