Cancel event if subform has no records

  • Thread starter Thread starter leonie
  • Start date Start date
L

leonie

Hi!
I want to have a message box pop up if the subform is empty. I have
the following code so far, which works, except it doesn't allow me to
choose the subform's combo box after the message box has been
displayed. Any ideas what I should do?

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.frmRisks.Form.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "You have to enter a risk"

End If

End Sub


thanks!
 
leonie,

don't know if this will make a difference, but have you tried re-arranging
your If clause so that the message box gets executed before the Cancel?

HTH,
Brian
 
Sorry, that was a stupid suggestion, as the record on your main form will be
saved automatically when you move focuse to your subform control; hence your
message box will always get executed.

Brian
 
let me TRY to articulate this again. The Before Update event will fire
everytime you try to add a new record or change an existing record on the
main form. So any attempt to save a new record will be cancelled. You'll
need to rethink your approach.

HTH,
Brian
 
Hi Brian!
Thanks! I know, and it's been driving me insane. I've been spending
about 7 hours on this yesterday with no luck, I'm sure I'm just making
a silly mistake or missing something, but I just can't figure it out.

Any help out there??
 
Back
Top