Results 1 to 3 of 3
  1. #1
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

    Delete record on bound form via Button click

    I have a bound form and want to create an audit log. I have some audit code,but am having an issue (or a senior moment).


    If I select a record and use the DELETE KEY on the keyboard, I get a message box asking for confirmation of the delete; when I click Yes, the record is deleted, the log is updated appropriately.
    However, I have a button on the form (Delete This Record) and when clicked it will update the log and delete the record--BUT-- it does not give the option to confirm or cancel the delete operation?

    ??How to get code behind the button to ask for the confirmation?
    ?? Can you provide a sample vba?

    Any suggestions welcome.
    Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Code:
    if msgbox("Delete record?",vbQuestion+vbYesNo+vbDefaultButton2 ,"Confirm") =vbyes then
       docmd.setwarnings false
       docmd.openquery "qaAddLogQry
       docmd.setwarnings true
       docmd.openquery "qdDeleteRec"
    end if

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Thanks ranman.
    I did resolve my issue with this code

    Code:
    Private Sub btnDEL_Click()
    10  If ShowDebug Then Debug.Print "btnDEL_Click()"
    20  If Not Application.GetOption("Confirm Record Changes") Then
    30      Application.SetOption ("Confirm Record Changes"), True
    40  End If
    50  If MsgBox("Do you want to delete this record?", vbOKCancel, "Delete Button") <> vbOK Then
    60      Exit Sub
    70  Else
    80      DoCmd.RunCommand acCmdDeleteRecord  ' Delete the record
    90  End If
    
    End Sub
    I was trying to use Form events eg Form.Delete, .BeforeDelConfirm, AfterDelConfirm but was not getting a message from Access.
    Adding my own message, and the DoCmd resolves it.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2014, 03:07 PM
  2. Replies: 1
    Last Post: 09-07-2014, 10:15 PM
  3. Replies: 1
    Last Post: 08-21-2014, 02:29 PM
  4. Replies: 1
    Last Post: 06-21-2013, 10:41 AM
  5. Replies: 4
    Last Post: 07-22-2011, 12:52 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