Results 1 to 3 of 3

Cancel New Record

  1. #1
    tralph01 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018

    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

    ElseIf Not IsNull(Me.Lname_Corrsp) Then

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
    End If

    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 offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    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 is online now Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Essex UK
    If you want to use code, then perhaps something like:
        On Error GoTo ErrorHandler    
        If Me.Dirty Then
        End If
        DoCmd.RunCommand acCmdDeleteRecord
        Exit Sub
        If Err.Number = 2046 Or Err.Number = 2501 Then
            Resume Next
            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.
    Not everyone can access an accdb, you may reach a broader audience by attaching in mdb format.

    Bob Fitzpatrick

    I have never failed. I have found a thousand ways that do not work!

    Microsoft Community Contributor Award (2011)

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

Similar Threads

  1. Replies: 11
    Last Post: 07-09-2014, 08:50 AM
  2. Replies: 5
    Last Post: 05-27-2014, 01:44 PM
  3. Replies: 5
    Last Post: 12-12-2013, 09:13 PM
  4. Cancel and Delete Record
    By Loc in forum Programming
    Replies: 3
    Last Post: 07-11-2013, 01:50 AM
  5. Cancel new record
    By oakoen in forum Forms
    Replies: 11
    Last Post: 12-18-2010, 08: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
Tech Forums: Microsoft Office Forums