How to assess a blank query

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

Guest

I have a form based on a query. On occasion the query returns no records
(appropriately so) and that makes the form completely blank, except for
what's in the header and footer.

I want to be able to assess the query and if it is empty then display a text
box that says something like, "There are no teacher records available to
activate."

I think I would attach it to the "on current" action, but I don't know how
to write the code.

Any help?

Jerry
 
Jerry,

The Current event is not the one you want here; it fires every time you
move into a record (new or existing), while all you need is an event
that fires once when you open the form. The Open and Load events are
such (and fire in that order). Assuming you use the Open event, all you
need is this code:

Private Sub Form_Open(Cancel As Integer)
If Me.Recordset.RecordCount = 0 Then
MsgBox "There are no teacher records available to activate."
DoCmd.Close acForm, Me.Name
End If
End Sub

HTH,
Nikos
 
Thanks, Nikos. I had figured out the first part through an earlier post, but
your Message Box idea made it "perfect!"

Jerry
 
Back
Top