Form OnDelete event

S

Steven

I have the following to not allow a user to delete more than one record at a
time in the form. The issue is that if more than one record (for example if
3 records were selected) then the MsgBox will show 3 times and etc.

How would you make it so the MsgBox will appear only one time?

Private Sub Form_Delete(Cancel As Integer)
If Me.SelHeight > 1 Then
Cancel = True
MsgBox "Cannot delete more than one record at a time."
Exit Sub
End If
'....continue
End Sub

Thank you,

Steven
 
S

Steven

I did a workaround by setting up a Public variable in the form's code and
then counting how many passes had been made through the On Delete and used
logic to test the count to the SelHeight to make it so the MsgBox would only
show one time.
 
D

Dirk Goldgar

Steven said:
I have the following to not allow a user to delete more than one record at
a
time in the form. The issue is that if more than one record (for example
if
3 records were selected) then the MsgBox will show 3 times and etc.

How would you make it so the MsgBox will appear only one time?

Private Sub Form_Delete(Cancel As Integer)
If Me.SelHeight > 1 Then
Cancel = True
MsgBox "Cannot delete more than one record at a time."
Exit Sub
End If
'....continue
End Sub

This seems to work:

'----- start of code -----
Private Sub Form_Delete(Cancel As Integer)

Static NDeletes As Integer

NDeletes = NDeletes + 1

If Me.SelHeight > 1 Then
Cancel = True
If NDeletes = Me.SelHeight Then
MsgBox "Cannot delete more than one record at a time."
NDeletes = 0
End If
Else
NDeletes = 0
End If

End Sub

'----- end of code -----
 
S

Steven

Dirk,

I was able to make it work basically with something like you did but I did
not use Static ...... That is interesting. Thank you.

Steven
 

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