Getting other field's value in the table

C

Chris L

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
 
R

ruralguy via AccessMonster.com

What is the DLookUp() code you are using? Are you asking for the UserID?
 
C

Chris L

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
 
R

ruralguy via AccessMonster.com

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]
 

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