Show Msgbox and Close Form

Show Msgbox and Close Form

Post by Carl Manka » Sat, 29 Oct 2005 09:39:12


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

--
Wishing you a VERY HAPPY NEW YEAR!!
May it far exceed your expectations.
 
 
 

Show Msgbox and Close Form

Post by fred » Sat, 29 Oct 2005 10:48:51


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

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 
 
 

Show Msgbox and Close Form

Post by Carl Manka » Sat, 29 Oct 2005 13:23:37

Thanks Fred. I'll give it a try.

Carl

--
Wishing you a VERY HAPPY NEW YEAR!!
May it far exceed your expectations.
 
 
 

Show Msgbox and Close Form

Post by Carl Manka » Sat, 29 Oct 2005 13:36:51

I know this is off topic but can someone point me to the correct place?
What is the equivalent to "RecordsetClone.RecordCount" For forms?

If Me.RecordsetClone.RecordCount = 0 Then


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

TIA,
Carl

--


--
Wishing you a VERY HAPPY NEW YEAR!!
May it far exceed your expectations.
 
 
 

Show Msgbox and Close Form

Post by Carl Rapso » Sun, 30 Oct 2005 00:21:26

If I'm not mistaken, you can't use the RecordsetClone in the Form_Open
event, as the form has not yet been populated. You might try placing your
code in the Form_Load event, and calling DoCmd.Close to close the form.

HTH,

Carl Rapson