Display Message 'No Data' for a Query

J

Jani

Is there a way to display a message 'No Data' for a query similar to what can
be done with a report?

Thanks, Jani
 
M

mscertified

Yes, If you open a recordset on the query and read the first record. If you
hit eof on the first read, its empty and you can put out your message.

-Dorian
 
J

Jani

Dorian, thanks for the reply but I don't understand your message. Can you
explain further. If the query produces no records, I want a message displayed
- not a blank record. Thanks! Jani
 
F

freakazeud

Hi,
use the dcount function to check if the query has data or not, based on that
evaluation you can give your message:

If Dcount("*","YourQuery") = 0 Then
Msgbox("No data!")
End If

HTH
Good luck
 
F

fredg

Is there a way to display a message 'No Data' for a query similar to what can
be done with a report?

Thanks, Jani

Not if you are opening the query itself directly from the main
database folder.
However, if you create a form, using the query as it's record source,
you can code the Form's Open event:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records"
Cancel = True ' Optional
End If

Open the Form.
The form will display your message and not open if there are no
records.
Set the Form's DefaultView property to Datasheet.
It will look just like the query datasheet.
 
Top