Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the result of a query in code

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
I have an append query that I execute with docmd.openquery in the click event of a command button on a form. What I would like to do is insert a search of one of the tables for the existence of a record. I would insert this before the docmd.openquery. I need to know if the record exists. I would like to use a SELECT statement instead of Dlookup. I can't find anything in the documentation about openquery setting a return code.

How do I query a table in code and get a found/not found result?

Robert
 
In code the simplest way is DLookUp or DCount.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try something like this:

Dim sSQL as string
Dim rs as RecordSet

sSQL = "SELECT * FROM
WHERE [Field]=" & YourValue

Set rs = CurrentDB.OpenRecordset(sSQL)

IF rs.RecordCount>0 THEN
MsgBox "Record Already Exists", vbInformation
ELSE
CurrentDB.Execute YourQuery
Msgbox "Record Was Inserted", vbInformation
END IF

rs.Close
Set rs = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top