Count of Query results = 0

S

shmoussa

Hi,

I have a button on my form. I want it so that when I click this
button, it will check the count of the results in my query1 query. If
the count is zero, I would like a popup that says "There are no
records found." If the count is 1 or greater, I would like it to run
and display that query. Any idea how to accomplish this?

Thanks
 
M

Marshall Barton

shmoussa said:
I have a button on my form. I want it so that when I click this
button, it will check the count of the results in my query1 query. If
the count is zero, I would like a popup that says "There are no
records found." If the count is 1 or greater, I would like it to run
and display that query. Any idea how to accomplish this?

Displaying a query as a datasheet is kind of crude, but this
kind of code should do that:

If DCount("*", "query1") > 0 Then
DoCmd.OpenQuery "query1"
Else
MsgBox "There are no records found."
End If
 
S

shm135

Displaying a query as a datasheet is kind of crude, but this
kind of code should do that:

If DCount("*", "query1") > 0 Then
        DoCmd.OpenQuery "query1"
Else
        MsgBox "There are no records found."
End If

Thanks! Worked perfectly!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top