Results 1 to 4 of 4
  1. #1
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27

    Cancel and Delete Record

    Here is my problem,

    In this form I am looking to add a record but I want to be able to cancel and delete this addition if they change there mind. The catch is if they don't enter any data then there is no record and I get the error no current record. Is there code I can use to check and tell it to just close the form if it's a new record?

    Here is my code
    Private Sub cmdCancel_Click()
    On Error GoTo errr



    If MsgBox("Cancel this record?", vbQuestion + vbYesNo, "Delete") = vbYes Then
    If MsgBox("Do you realy want to cancel the record", vbQuestion + vbYesNo, "delete") = vbYes Then
    Me.Recordset.Delete
    DoCmd.Close
    End If
    End If

    errr:
    MsgBox Err.Description
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try:
    Code:
    Private Sub cmdCancel_Click()
       On Error GoTo errr
    
       If MsgBox("Cancel this record?", vbQuestion + vbYesNo, "Delete") = vbYes Then
          If MsgBox("Do you realy want to cancel the record", vbQuestion + vbYesNo, "delete") = vbYes Then
             Me.Recordset.Delete
             DoCmd.Close
          End If
       End If
    
    errr:
       If Err.Number <> 3021 Then
          MsgBox Err.Description
       End If
    
    End Sub

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You could only execute the deletion code if the Record is actually Dirty:
    Code:
    Private Sub cmdCancel_Click()
    On Error GoTo errr
    
    If Me.Dirty Then
     If MsgBox("Cancel this record?", vbQuestion + vbYesNo, "Delete") = vbYes Then
      If MsgBox("Do you realy want to cancel the record", vbQuestion + vbYesNo, "delete") = vbYes Then
       Me.Recordset.Delete
       DoCmd.Close
      End If
     End If
    Else
     DoCmd.Close
    End If
    errr:
    MsgBox Err.Description
    End Sub
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27
    Missinglinq,
    This worked but I get a message box with no information in it and just an OK button when I run the code.
    Now I get the no current record error when the record has information in it.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-03-2013, 10:02 AM
  2. Replies: 12
    Last Post: 10-27-2012, 05:44 AM
  3. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  4. Trying to Delete record using delete query
    By MooseOTL in forum Access
    Replies: 13
    Last Post: 10-04-2011, 02:30 AM
  5. Cancel new record
    By oakoen in forum Forms
    Replies: 11
    Last Post: 12-18-2010, 09:26 AM

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