Getting other field's value in the table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a table called tblUser with UserID as the primary key and some other
fields such as UserName, Company, etc
I want to prevent duplicate with the UserName field and at the same time I
want to get the corresponding UserID if the UserName field has already
existed.

I can prevent duplicate by using DLookup, but I'm stucked in getting the
UserID, can anyone help me...

Regards,
Chris
 
What is the DLookUp() code you are using? Are you asking for the UserID?
 
Hi,

The source code is roughly like this.

x = DLookup("[UserName]", "tblUser", "[UserName]= '" & strUserName & "'")

If IsNull(x) Then
'Add new UserName
Else
'I want to get the UserID of the existing UserName
End If

Regards,
Chris
 
How about doing something like:

Dim x As Variant

x = DLookup("[UserID]", "tblUser", "[UserName]= '" & strUserName & "'")

If you have a match then x = UserID


Chris said:
Hi,

The source code is roughly like this.

x = DLookup("[UserName]", "tblUser", "[UserName]= '" & strUserName & "'")

If IsNull(x) Then
'Add new UserName
Else
'I want to get the UserID of the existing UserName
End If

Regards,
Chris
What is the DLookUp() code you are using? Are you asking for the UserID?
[quoted text clipped - 11 lines]
 
Back
Top