Checking If Recordset Returns Any Rows

J

JamesJ

Hi. I have a continuous form that is based on a select statement
that checks the value of a record's check box. If the check box's
value is Yes the record is displayed.
Simply put there are times when I am certain the recordset will
return no records. When no records are returned the form opens
fine but nothing at all is displayed.
I would like to check for no records and then display a MsgBox
or add an unbound label to be displayed only if there are no records.
How can I check for no records?? I considered checking the
recordset's BOF and the EOF or the Recordcount but don't know
were to start. Any help will be appreciated.

Thanks,
James
 
J

Jim Allensworth

Hi. I have a continuous form that is based on a select statement
that checks the value of a record's check box. If the check box's
value is Yes the record is displayed.
Simply put there are times when I am certain the recordset will
return no records. When no records are returned the form opens
fine but nothing at all is displayed.
I would like to check for no records and then display a MsgBox
or add an unbound label to be displayed only if there are no records.
How can I check for no records?? I considered checking the
recordset's BOF and the EOF or the Recordcount but don't know
were to start. Any help will be appreciated.

Thanks,
James

Use the form's Open event to check the records with the
RecordsetClone.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
'No records
MsgBox "No records to display!"
Cancel = True
End If
End Sub


- Jim
 
J

JamesJ

That'll work! Thanks, Jim.

Thanks again,
James

Jim Allensworth said:
Use the form's Open event to check the records with the
RecordsetClone.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
'No records
MsgBox "No records to display!"
Cancel = True
End If
End Sub


- Jim
 
J

JamesJ

One slight problem. Now I get Runtime Error 2501
"OpenForm action was canceled"

James
 

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