On Delete event repeats

B

Brad P

An On Delete event on a subform repeats when I delete a record (when the
condition is true) in that subform. Here is the code:

If Me![Staff] <> Forms![frm_StaffInitials]![Initials] Then
MsgBox "You can not delete a Time Expense created by another user"
DoCmd.CancelEvent
Exit Sub
End If

Not sure why....any suggestions?

Thanks
 
A

Allen Browne

The event should repeat if you selected two rows at once (in a continuous
form or datasheet).

If that's not the case, is there anything similar in the BeforeDelConfirm or
AfterDelConfirm events?

You could also try replacing:
DoCmd.CancelEvent
with:
Cancel = True
since the event provides a Cancel argument.
 
B

Brad P

Allen Browne said:
The event should repeat if you selected two rows at once (in a continuous
form or datasheet).

Its only one record I select in a continuous form.
If that's not the case, is there anything similar in the BeforeDelConfirm or
AfterDelConfirm events?
Nothing.

You could also try replacing:
DoCmd.CancelEvent
with:
Cancel = True
since the event provides a Cancel argument.

Tried that suggestion, same thing. I know that the On Delete event itself
runs twice as I watched the code run.

I use the record selector on the form, hit the Delete key. I get my prompt
twice. Weird /-| haha

Thanks Allen for the reply
Brad
 
B

Brad P

I tried opening the subform by itself and the Delete event ran once, so it
has something to do with it being a subform. Interesting.
 
A

Allen Browne

Brad the only other suggestion I have is to check that you have the correct
service pack for your version of Access.

Help | About will give you your version number and service pack.
support.microsoft.com will take you to the latest service pack.
 
B

Brad P

I have 9.0.4402-SR1.

I'm going to play around with it today, if I figure out what is going on, I
will post it.

Thankss
Brad
 

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