Results 1 to 3 of 3
  1. #1
    tralph01 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    1

    Cancel New Record

    I'm extremely new at this, so apologize, but here's what I was intending. Using a front end/back end database setup. Front end user opens the database to create a record. Clicks a button that takes him or her to a new form where he or she can enter the data. All good and working well. I understand that at this point the new record is NOT created until the user actually clicks in a box or moves to a new record. I would like a cancel button here. I've learned that if the user created a record, it needs to be deleted at this time. If the user, hasn't done anything, then an undo is necessary as the record does not exist and a delete will cause an error...



    Here is what I was hoping might work:

    If IsNull(Me.Lname_Corrsp) Then
    Me.Undo


    ElseIf Not IsNull(Me.Lname_Corrsp) Then

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
    End If

    DoCmd.Close
    DoCmd.OpenForm "opening menu", acNormal, , , acFormReadOnly

    End Sub




    It doesn't seem work though. I feel as though I'm close...but when I run this, the delete works perfectly if I enter a field value, but when a record has not been created (i.e. I do nothing but click the cancel button I create, it still tries to delete and I get an error....). Is the Null my problem? I've added this to an OnClick to a control button BTW.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you dont reallly need code,
    just hit ESC button and the record will vanish. (as long as they dont save it 1st. Then press DEL button)

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    If you want to use code, then perhaps something like:
    Code:
        On Error GoTo ErrorHandler    
        If Me.Dirty Then
           Me.Undo
        End If
        
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.Close
        Exit Sub
    
    
    ErrorHandler:
        If Err.Number = 2046 Or Err.Number = 2501 Then
            Resume Next
        Else
            MsgBox "Error Number " & Err.Number & " " & Err.Description
        End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 11
    Last Post: 07-09-2014, 09:50 AM
  2. Replies: 5
    Last Post: 05-27-2014, 02:44 PM
  3. Replies: 5
    Last Post: 12-12-2013, 10:13 PM
  4. Cancel and Delete Record
    By Loc in forum Programming
    Replies: 3
    Last Post: 07-11-2013, 02:50 AM
  5. Cancel new record
    By oakoen in forum Forms
    Replies: 11
    Last Post: 12-18-2010, 09:26 AM

Tags for this Thread

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