Show Msgbox and Close Form

C

Carl Mankat

I am running Access 2K on a W2K machine.

I want to test a form to see if it has any records and if not close the
form.


Code that works:

Private Sub Form_Activate()
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Choose a room number between 1 & 44"
End If
End Sub

I'd like to include DoCmd Close but this seems to cause errors. Can I
combine that statement in this event or should I creates a new event?

TIA,

Carl
 
F

fredg

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Choose a room number between 1 & 44"
End If

Place your code in the form's Open event, then cancel the event if
there are no records.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Choose a room number between 1 & 44"
Cancel = true
End If
End Sub
 

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