DLookup Question

  • Thread starter Thread starter Steve Haack
  • Start date Start date
S

Steve Haack

I am new to Access, and I am having a bit of trouble getting DLookup to work.
Here is the scenario:

I have a modal form, which is asking the user to enter an ID Card Number,
and then I do a search to see if there is a Player with that card number in
the system.

I want to use DLookup to do that search, but I am getting all sorts of
errors. I think it might be a type mistmatch, but I'm not sure.

The table I want to search is called tblPayers, the field that I want to
search is called PlayerCardID, and it is a text field, but the contents is a
number, like 1001, etc.

Can someone please help?
 
Steve Haack said:
I am new to Access, and I am having a bit of trouble getting DLookup to
work.
Here is the scenario:

I have a modal form, which is asking the user to enter an ID Card Number,
and then I do a search to see if there is a Player with that card number
in
the system.

I want to use DLookup to do that search, but I am getting all sorts of
errors. I think it might be a type mistmatch, but I'm not sure.

The table I want to search is called tblPayers, the field that I want to
search is called PlayerCardID, and it is a text field, but the contents is
a
number, like 1001, etc.

Can someone please help?


If the field is a text field, you still have to put quotes around the value.
Try something like this:

'----- start of example code -----
If IsNull( _
DLookup( _
"PlayerCardID", "tblPlayers", _
"PlayerCardID='" & Me!IDCardNumber & "'") _
) _
Then
' This card is not on file.
Else
' This card is already on file.
End If
'----- end of example code -----

In the above, I've assumed that "IDCardNumber" is the name of the text box
on the form, into which the user has entered the card number.
 
Hi Steve Haack,

if isnull(dlookup("PlayerCardID","tblPayers","PlayerCardID=""" &
thecardyouresearching & """") then
msgbox "Card not found"
else
msgbox "Card found"
endif

HTH Paolo
 
Steve said:
I am new to Access, and I am having a bit of trouble getting DLookup to work.
Here is the scenario:

I have a modal form, which is asking the user to enter an ID Card Number,
and then I do a search to see if there is a Player with that card number in
the system.

I want to use DLookup to do that search, but I am getting all sorts of
errors. I think it might be a type mistmatch, but I'm not sure.

The table I want to search is called tblPayers, the field that I want to
search is called PlayerCardID, and it is a text field, but the contents is a
number, like 1001, etc.


Try something like:

DLookup("Player", "tblPayers", "PlayerCardID= '" & Me.[ID
Card No] & "' "
 
Thanks to everyone for the replies. I was able to get it working.

Steve

Marshall Barton said:
Steve said:
I am new to Access, and I am having a bit of trouble getting DLookup to work.
Here is the scenario:

I have a modal form, which is asking the user to enter an ID Card Number,
and then I do a search to see if there is a Player with that card number in
the system.

I want to use DLookup to do that search, but I am getting all sorts of
errors. I think it might be a type mistmatch, but I'm not sure.

The table I want to search is called tblPayers, the field that I want to
search is called PlayerCardID, and it is a text field, but the contents is a
number, like 1001, etc.


Try something like:

DLookup("Player", "tblPayers", "PlayerCardID= '" & Me.[ID
Card No] & "' "
 
Back
Top