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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA - Checking whether a record exists in a table 1

Status
Not open for further replies.

lionelfridjhon

Programmer
May 21, 2007
2
0
0
US
The user enters a value in a textbox and the program then builds a SQL query to find a single record by searching the key field of the table and then previews the record in a report.
Works fine unless the user enters an invalid value in the text box. Then the report shows errors in all fields.
How can I trap this error, and respond with an appropriate messageBox instructing the user to retry?

I tried using the FindRecord Method, but do not get a result which indicates whether the requested record exists or not.

A reply will be appreciated.
 
Why not using the NoData event of the report ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Try using the dcount method:

If dcount("Fieldname", "Queryname") = 0 then
Msgbox "There is no data to display"
exit sub
end if

HTH
Rich

Bespoke and off-the-shelf Access solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top