Testing for empty recordset before opening form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am opening a form, frmFeedbackCollection, that I use to populate part of a
database. The recordsource for the form, right now, is a query that runs
just fine by itself. I would like to implement a test to see if the query is
returning 0 records and then stop the form from opening in that case.

I need some recommendations on how best to do that:

(1) should I test when the user clicks the button that opens the
frmFeedbackCollection by creating a recordset based on the same SQL string
as the query and then testing the recordcount property (this seems redundant
since if the recordcount is not zero, the form opens by running the query
again)?
(2) should I test the recordcount in the onOpen event of the
frmFeedbackCollection? I am not sure how to do this without creating a
recordset clone again, and then isn't there a redundancy issue like the one
mentioned above?

Any recommendations?

bj
 
Cancel the Open event of the form if its RecordsetClone has a zero
RecordCount:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "No records"
End If
End Sub
 
Back
Top