Results 1 to 5 of 5
  1. #1
    ItsATJ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2013
    Posts
    11

    Custom BeforeDelConfirm Message Question/Problem

    I have created a custom BeforeDelConfirm dialog box using the following code:



    Code:
    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
        ' Supress Default Delete Confirmation dialog box.
        Response = acDataErrContinue
    
        ' Display custom dialog box.
        If MsgBox("Are you sure you want to delete this MEF?", vbYesNo) = vbNo Then
            No = True
        End If
    End Sub
    And a custom AfterDelConfirm dialog box using the following code:

    Code:
    Private Sub Form_AfterDelConfirm(Status As Integer)
        Select Case Status
        Case acDeleteYes
            MsgBox "The MEF has been deleted."
        Case acDeleteNo
            MsgBox "The MEF has not been deleted"
        Case acDeleteUserNo
            MsgBox "The MEF has not been deleted."
        End Select
    End Sub
    I have a "Delete This MEF?" button that I created with the button wizard.

    The problem is, if I want to delete record 1, I click on the delete button, Access advances to record 2 and asks "Are you sure you want to delete this MEF?". If I say "Yes", Access will delete record 1 and continue to show record 2. Is this behavior normal? I would like it to stay on record 1 when it asks it's confirmation message, then advance to record 2 after the delete.

    If possible, I would like Access to insert the MEF number to be deleted into the question - "Are you sure you want to delete MEF 1?"

    Any help will be highly appreciated.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    I have a "Delete This MEF?" button that I created with the button wizard.
    Why not put a msgbox in the OnClick event of this button that requests confirmation of the wish to delete the current record. Only allow the lines of code that do the deleting to run if it was confirmed by the msgbox.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ItsATJ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2013
    Posts
    11
    Thanks for the quick reply.

    The macro associated with the OnClick for the "Delete This MEF?" button has 7 action items:

    Code:
    Condition - Action - Arguments
     - OnError - Next,
     - GoToControl - =[Screen].[PreviousControl].[Name] 
     - ClearMacroError -
    Not [Form].[NewRecord] - RunCommand - DeleteRecord
    [Form].[NewRecord] And Not [Form].[Dirty] - Beep - 
    [Form].[NewRecord] And [Form].[Dirty] -RunCommand - Undo
    [MacroError]<>0 - MsgBox - =[MacroError].[Description], Yes, None
    How should I modify the macro to get what I need?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    I'm afraid I don't do macros, but the code below should work for you if you put it in the buttons OnClick event. Be sure to include the error handling code.
    Code:
    On Error GoTo ErrorHandler
      
      If MsgBox("Are you sure you want to delete this MEF?", vbYesNo, "Confirmation Required") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
      End If
      
    Exit_ErrorHandler:
      DoCmd.SetWarnings True
      Exit Sub
    ErrorHandler:
        MsgBox Err.Description
        Resume Exit_ErrorHandler
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    ItsATJ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2013
    Posts
    11
    I have deleted my two form codes, removed the macro attached to the button and copied your code into the button's OnClick event code.

    Works perfectly.

    Thanks for all your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 12-31-2012, 10:41 PM
  2. Replies: 14
    Last Post: 06-06-2012, 12:50 PM
  3. Custom validation error message
    By snorkyller in forum Access
    Replies: 2
    Last Post: 03-21-2011, 03:40 PM
  4. Custom error message problem
    By thekruser in forum Programming
    Replies: 10
    Last Post: 10-06-2010, 05:14 PM
  5. Creating a *Good* Custom Message Box
    By Jerimiah33 in forum Forms
    Replies: 1
    Last Post: 11-09-2005, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums