Bawn
Bawn

Reputation: 509

Checking if a record exists using two fields

I have two fields that are going to be scanned into my form, I have a button on the form and when its pressed I want a Dialog box saying weather the record exists. I currently have an SQL query that pulls the record from the database.

SELECT Stock, Scanned
FROM Products
WHERE ((([Stock])=Forms!Products![Stock Code]))                                                  
And ((([Scanned])=Forms!Products![Scanned Information]));

I want to be able to check if this query returns null or not. I'm not sure if this is even the best way to check if a record exits, would DLookup be a better approach for what i'm trying to achieve ?

Upvotes: 0

Views: 446

Answers (1)

smoore4
smoore4

Reputation: 4866

Something like this should work:

Set db = CurrentDb
Set qdf = db.QueryDefs("mySelectQuery")
Set rs = qdf.OpenRecordset()
if rs.EOF then
MsgBox "The record does not exist"
else
MsgBox "The record does exist"
end if

Upvotes: 1

Related Questions