Results 1 to 13 of 13
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deletion Warning Messages (A2K)

    This is the standard VB code for deleting a record and it works:

    Private Sub Command686_Click()
    On Error GoTo Err_Command686_Click

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Exit_Command686_Click:
    Exit Sub
    Err_Command686_Click:
    MsgBox Err.Description
    Resume Exit_Command686_Click
    End Sub

    I've tried the following in order to give the user two chances to back out of their deletion:

    Private Sub DeleteCurrentRecord_DblClick(Cancel As Integer)
    On Error GoTo Err_DeleteCurrentRecord_Click

    ' Warning Messages Start Here
    Dim intResponse As Integer
    Dim DoYouMeanIt
    DoYouMeanIt = MsgBox("Are You Sure You Want to Delete This Model?", vbYesNo, "This Model Will No Longer Exist!!")
    If DoYouMeanIt = vbYes Then
    DoYouMeanIt = MsgBox("Are You Absolutely Sure You Want to Delete This Model?", vbYesNo, "This Model Will Totally Disappear!!")

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Else
    intResponse = acDataErrContinue
    End If
    Exit_DeleteCurrentRecord_Click:
    Exit Sub
    Err_DeleteCurrentRecord_Click:
    MsgBox Err.Description
    Resume Exit_DeleteCurrentRecord_Click
    End Sub

    The messages come up very nicely, but the record does not get deleted. Would someone be kind enough to show me what I'm missing
    Cheers,
    Andy

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Deletion Warning Messages (A2K)

    It's hard to tell why when you're using the old wizard-built Access 95 code that is outdated in 97 and later. Why Microsoft hasn't really updated the wizards is a question that leads to all sorts of angry discussion, but you'll certainly have more readable code if you use the RunCommand statements instead of those old 95-menu based statements.

    Since I can't remember what the menu references were and the menus have changed over the versions, here's some more readable code to delete the current record.

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True
    Charlotte

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Warning Messages (A2K)

    As a user, I would quickly become irritated by this code - I don't like being asked the same question twice.

    I don't understand why you put this in the On Dbl Click event of a control. I don't understand the role of the intResponse variable either - you assign a value, but do nothing with it in the rest of the code, so Access will ignore it. And you don't do anything with the value of DoYouMeanIt after the second message box, so the lines after it are run regardless of which button the user clicked.

    The code using DoMenuItem is obsolete. That is not your fault - for some reason, Microsoft never adapted the code from the old wizards. But for readability, it's better to use RunCommand acCmdDelete instead of the two lines with DoMenuItem.

    Unless you have turned off the default warning, Access will still prompt the user if the record should be deleted AFTER your two messages.

    Here is code that should work (irritatingly):

    Private Sub DeleteCurrentRecord_Click()
    On Error GoTo Err_DeleteCurrentRecord_Click
    If MsgBox("Are You Sure You Want to Delete This Model?", _
    vbYesNo + vbQuestion, _
    "This Model Will No Longer Exist!!") = vbYes Then
    If MsgBox("Are You Absolutely Sure You Want to Delete This Model?", _
    vbYesNo + vbQuestion, _
    "This Model Will Totally Disappear!!") = vbYes Then
    DoCmd.SetWarnings False
    RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True
    End If
    End If
    Exit Sub

    Err_DeleteCurrentRecord_Click:
    MsgBox Err.Description, vbExclamation
    End Sub

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Hans,

    As always a quick response. Believe it or not, this double message approach to deleting a record was specifically requested for by the user. Including the DoubleClick. Said user has been trigger happy in the past and has deleted too quickly and therefore wants a really big heads up.

    With respect to the code I used, I did not originate it and can therefore not really explain the need or lack of need for certain lines such as intResponse variables within the code. I totally depend on those that know, like yourselves, how to put together code that works. My main thing is to try and put together the correct pieces of code in a manner that satisfies the user.

    I appreciate your pointing out that the code that I did use, such as DoMenuItem is not totally my fault. I had a marvelous response for Charlotte questioning whether or not I was the culprit in all of this. I certainly felt guilty.

    So, I put in the code you suggested and got the message "The command or action 'Delete Record' isn't available now. Sigh! What did I do this time?
    Cheers,
    Andy

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Warning Messages (A2K)

    Did you get that message while trying to single-step through the code, or while you were on a new (not yet saved) record? If the former, that it to be expected - not all code works properly when single-stepping. If the latter, you might build in a check at the beginning of the procedure to avoid trying to delete a new record:

    If Me.NewRecord Then Exit Sub

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Hans, it was an existing record and the double-click was applied as if I were the trigger happy user.
    Cheers,
    Andy

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Warning Messages (A2K)

    Can you delete a record the usual way, by clicking the Delete button in the toolbar?

  8. #8
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Yes I can. I was also able to delete a record using the old-fashioned Delete Command Button when I had one on the form and before I went into double-messaging mode.
    Cheers,
    Andy

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Warning Messages (A2K)

    The code I posted higher up worked correctly in my test database. If you can't find out what's wrong, we'll have to see the database. You know the recipe...

  10. #10
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Hans,
    Just to double check, I tried deleting records again, and, oddly enough, it deletes some of the records some of the time, but not all of the records all of the time. That is it will delete two in row and then give me the message and then I can delete again and so on back and forth. Weird. I'll try to see if there is a pattern.

    Andy
    Cheers,
    Andy

  11. #11
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Hans, thanks for the offer, I'll follow up on this tomorrow morning. 9:30 p.m. here.

    Andy
    Cheers,
    Andy

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Deletion Warning Messages (A2K)

    Did you put that code in the DoubleClick event? If so, I would expect an error message unless you pasted the body of the code into a wizard generated event procedure, since Doubleclick has a Cancel argument but Click doesn't.

    One question Hans hasn't asked is WHERE your button is located. If it is on a toolbar or on a parent form when you're trying to delete a record in a subform, that could also cause the problem. Is the focus in the current record just before you double click the button? Is the record dirty when you try and delete it?
    Charlotte

  13. #13
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Warning Messages (A2K)

    Charlotte, I appreciate your jumping in.

    First the good news, it now works. Here is what I did just prior to receiving your message:
    The button is on the form and not a toolbar.
    Changed from DoubleClick to SingleClick just in case.
    No difference.
    Strange pattern of deletions. It was deleting on every 3rd attempt suggesting that something else was affecting the deletion process.
    Noticed small subform (continuous) which was displaying the available filtered records within the group that I was working on.
    Saw the #Deleted record on the display and said, HHHmmmm!
    I got rid of the SubForm and Voila, the little @#$!% works.

    My thanks to you and Hans for helping me get through this.
    Cheers,
    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •