Dlookup (two fields)

L

learning_codes

Hi,

I want to know how to add extra line (UserName) for two DLookup on
UserID and UserName.

Search_UserID = Me.UserID
Search_UserName = Me.TxtName.Value

CHECK_UserID_UserName = DLookup("[UserID]", "Tbl_Employees",
"([UserID]) like ""*" & Search_UserId & "*""")

Your help would be much appreciated.
Thanks
 
D

Douglas J. Steele

The usual way is to have two separate lookups.

It is possible to have a single DLookup return more than one value, but if
you do that, then you have the issue of separating the multiple values
returned.
 
L

learning_codes

The usual way is to have two separate lookups.

It is possible to have a single DLookup return more than one value, but if
you do that, then you have the issue of separating the multiple values
returned.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)




I want to know how to add extra line (UserName) for two DLookup on
UserID and UserName.
Search_UserID = Me.UserID
Search_UserName = Me.TxtName.Value
CHECK_UserID_UserName = DLookup("[UserID]", "Tbl_Employees",
"([UserID]) like ""*" & Search_UserId & "*""")
Your help would be much appreciated.
Thanks- Hide quoted text -

- Show quoted text -

Thanks Doug,

It will be like this at the same time ?....

Check_UserID = DLookup("[UserID]","Tbl_Employees","([UserID]) Like
""*" & Search_UserID & "*""")
Check_UserName = DLookup ("[UserName]","Tbl_Employees","([UserName])
Like ""*" & Search_UserName& "*""")

If (IsNull(Check_UserID)) and (IsNull(Check_UserName)) Then
........
.......
Else
......
......
End If

I would be more happy to hear if you can correct me if I'm wrong. I
would appreciated if you explain and show me what is right step.
I'm still learning how to use Dlookup.

Thanks
 
D

Douglas J. Steele

I want to know how to add extra line (UserName) for two DLookup on
UserID and UserName.
Search_UserID = Me.UserID
Search_UserName = Me.TxtName.Value
CHECK_UserID_UserName = DLookup("[UserID]", "Tbl_Employees",
"([UserID]) like ""*" & Search_UserId & "*""")
Your help would be much appreciated.
Thanks- Hide quoted text -

The usual way is to have two separate lookups.

It is possible to have a single DLookup return more than one value, but
if
you do that, then you have the issue of separating the multiple values
returned.

Thanks Doug,

It will be like this at the same time ?....

Check_UserID = DLookup("[UserID]","Tbl_Employees","([UserID]) Like
""*" & Search_UserID & "*""")
Check_UserName = DLookup ("[UserName]","Tbl_Employees","([UserName])
Like ""*" & Search_UserName& "*""")

If (IsNull(Check_UserID)) and (IsNull(Check_UserName)) Then
.......
......
Else
.....
.....
End If

I would be more happy to hear if you can correct me if I'm wrong. I
would appreciated if you explain and show me what is right step.
I'm still learning how to use Dlookup.

Without knowing exactly what you're trying to accomplish, that code looks
valid.

However, since you're using Like and wild cards, there's no guarantee that
you're going to be returning what you're looking for. As well, you have no
way of knowing that the UserID and UserName correspond to the same person.

You might be better off using:

Check_UserID = DLookup("[UserID]","Tbl_Employees","[UserID] Like
""*" & Search_UserID & "*"" And [UserName Like ""*" & Search_UserName &
"*""")
Check_UserName = DLookup ("[UserName]","Tbl_Employees","[UserID] Like
""*" & Search_UserID & "*"" And [UserName Like ""*" & Search_UserName &
"*""")

If IsNull(Check_UserID) and IsNull(Check_UserName) Then
.......
......
Else
.....
.....
End If

In fact, you might want to use Or, rather than And in your If statement:

If IsNull(Check_UserID) Or IsNull(Check_UserName) Then
 

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

Similar Threads


Top