Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Cedar Falls, Iowa, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    abort new record (a2000)

    How do I allow a user to back out of a new record without generating the null value error when the field they have begun entry on is the PK for the record?

    E

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: abort new record (a2000)

    The user can press Esc once or twice (depending on how much has been entered in the record.)

    You can also provide an "Undo record" button that cancels the new document:

    Private Sub cmdUndo_Click()
    Me.Undo
    End Sub

    If you want to ask for confirmation:

    Private Sub cmdUmdo_Click()
    If MsgBox("Do you want to cancel changes to this record?", vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
    Me.Undo
    End If
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Cedar Falls, Iowa, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: abort new record (a2000)

    What about if it's a new record on a subform that they've started? I want them to be able to undo what they've done on the subform without undoing what they've done on the main form but don't want to locate undo command buttons on each subform.
    E

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: abort new record (a2000)

    You can't have a single Undo button on the main form, for when the user tries to click it, the subform loses focus and Access attempts to save the subform record.

    So teach them to use Esc to undo a record, and that it is important where the focus is when they press Esc.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: abort new record (a2000)

    You could validate the data in the beforeUpdate event of the subform and if key information is missing either ask the user if he wants to continue editing the record or throw it away automatically. An Undo button on the main form would then serve to delete both the parent and the subform records.
    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Cedar Falls, Iowa, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: abort new record (a2000)

    I saw the code for this in another thread with a sample database. What was messing me up was that the Undo wasn't working because I had the required property set to yes in the table. Looks like this wil do exactly what I wanted. Thanks for the suggestion!

    E

  7. #7
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: abort new record (a2000)

    I've found it better to use an unbound form to add records. That way it is easy for users to cancel by clicking on a cancel button that simply closes the form.

    An add button invokes a procedure that checks the validity of the data as necessary and if there are errors dumps the user back to the form with a message indicating the fault. If the data is valid then the new record is created and populated by code. Because the adding is done by code users do not need to be shown fields that I don't want them to see, yet I can write data to those fields invisibly. This works particularly well where data has to be written to several tables in which case a transaction is used.

    I use the same process with editing records where I populate an unbound form with the record, or part record, that is to be edited. Again it is easy to just close the form to cancel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •