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

Access/VBA Question

Status
Not open for further replies.

lamaar

Technical User
Jun 29, 2000
392
GB
I'm currently writing and Access (2000) DB with a graphics front end with the main bells ansd whistles coming out of a VBA package. I have a form that is linked to a query of the main table in the database. To bring up this form I want the user to click on a button. The problem is, that occasionally the resulting query may actually return no results. This results in a totally blank form with nothing on it which doesn't look too great. Could anyone tell me how I can get an if() statement to check if the query result will be empty before opening it?
ie:

if(query result has no results) then
MsgBox
Else
DoCmd.OpenForm

Thanks

Lamaar75@hotmail.com
 
Hi

Use the DCount function with an appropriate statement relating to the underlying SQL of your form to check that there will be at least 1 result before running it.

Eg

If DCount("*", "Tablename or queryname", "condition='x'") =0 then
Msgbox "No results found"
else
Docmd.openform "Formname"
end if

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top