Form_Delete called 2 times when using DEL key on subform

I am at a complete loss on this one...  I have a subform (continuous), inside a form, and I've got a custom-built Form_Delete section that works well.  The problem is, if the user selects delete (for 1 or multiple records) from the menu, the routine functions normally, and I am asked if I want to delete, or not delete, or cancel the remaining questions for each of the selected records.  If the user presses the DEL key, the process happens 2 times (all the selected items are listed for deletion, and, if the user selects "No, don't delete", once the last of the selected items has been asked, the entire process repeats itself (asking all the selected items that the user selected "No" for again.

Again, it works fine from the menu, but repeats 2 times when pressing the DEL key.
The form is a subform of another form, (when I use the form itself, not as a subform, the DEL key works fine)
I'm using Access 2003, and this feels like a bug, but any help would be greatly appreciated.
oronkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jadedataMS Access Systems CreatorCommented:
Hey oronk!

  If you are using the OnDelete Event to Delete a record, you are multiplying its effect.
  This is not a bug.

  Show the code for you Delete related events on the affected form(s) and specify which form the code rides on.

regards
Jack
0
oronkAuthor Commented:
This is the only event that is called (for either the menu delete, or the DEL key).  As I stated before, if the Menu Delete command is used, this routine is run 1 time for each record that is to be deleted (weather or not the record is deleted)... If the DEL key is pressed (not using the menu), this routine is run 1 time for each record, then another time for any of the records that were not to be deleted.  
You state that I am multiplying the effect... why and how would it multiply when pressing the DEL key, but not when selecting the Delete Records from the menu?

Private Sub Form_Delete(Cancel As Integer)
   Static Test As VbMsgBoxResult
   Static Records As Integer
   
   If Test = vbCancel And Records > 0 Then
      Cancel = True
      Records = Records - 1
   Else
      Dim rst As Recordset
      Dim strSearchName As String
      Set rst = Me.RecordsetClone
      strSearchName = Str(Me!LContactsID)
      rst.FindFirst "LContactsID = " & strSearchName
      If Not rst.NoMatch Then Records = rst.AbsolutePosition
      rst.Close
   
      Records = Me.SelHeight + (Me.SelTop - 1) - Records
      Test = MsgBox("Are you sure you want to delete: " & Chr$(13) & Chr$(10) & _
                    """" & ShortNameText & ": " & NameListingText.Value & """?", vbYesNoCancel, "Delete Contact")
      If Test = vbYes Then
         MsgBox "Deleting Current Record: " & NameListingText.Value & ": " & NameListingText.OldValue
      Else
         Records = Records - 1
         Cancel = True
      End If
   End If
End Sub
0
oronkAuthor Commented:
the main form does not include a OnDelete event, this resides in the subform.  Also, like I stated, if I run the subform as a stand-alone form, the DEL key only calls the function 1 time per record, not 2 times.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jadedataMS Access Systems CreatorCommented:
Move that code onto a separate button and out of the form_delete event.  
Delete the target record directly from the recordset it is found in.
Requery the form after a delete.

I bet the problem goes away
0
oronkAuthor Commented:
jadedata,
Your solution has crossed my mind... but I really want to be able to delete multiple records at the same time (which is why I use the form_delete event).  Using the button, from what I can tell, even if I had multiple selections, when I clicked on the button, only 1 record would be deleted.
Maybe I'm going about this wrong... is there anyway to tell that the DEL key was pressed... I don't think it's in the normal keypress information...  If I could tell from where the delete command came from, I could know what to expect (like duplicate requests to delete)
I would even be willing to use the Form_BeforeDelConfirm function (but I MySQL doesn't do transactions... once Access deletes a record, it can't be undeleted... as far as I can tell, which is why I ask in the Form_Delete routine)
0
oronkAuthor Commented:
I figured it out... The problem was on the form, I had Allow Deletes enabled, but I had Allow Edits disabled, for some reason, this combination of options caused the Form_Delete to run twice when the form was a subform of another form.
0
jadedataMS Access Systems CreatorCommented:
well, wasn't that a fun and educational ride!!?
0
stevbeCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

stevbe
EE Cleanup Volunteer
0
Mikal613Commented:
Make a Flag

Dim DelFlag as Boolean


Formload DelFlag = False

In your Delete Sub

Make the Flag True  and then false and then the Click event only call the Delete Procedure if the flag is true
0
SpazMODicCommented:
PAQed, with points refunded (250)

SpazMODic
EE Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.