Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Close Action Canceled (2002)

    Hi,

    I'm using the following code on the before update option:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    'Asks whether record should be saved
    If MsgBox("Do you want to save this record?", vbQuestion Or vbYesNo) = vbNo Then
    Me.Undo
    DoCmd.Close acForm, "frmPatientDemographics"
    End If
    End Sub

    It works fine if the user says yes. If the user says no there is an error that the close action was canceled. I don't understand why or what I'm missing.

    Thanks,
    Leesha

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

    Re: Close Action Canceled (2002)

    Is frmPatientDemographics the form containing this code? If there are other event procedures, trying to close the form during a Before Update event may well lead to conflicts. But without seeing the database, it's hard to say.

  3. #3
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close Action Canceled (2002)

    You also need to cancel the update.
    Add the line Cancel = True before Me.Undo.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  4. #4
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close Action Canceled (2002)

    Hi,

    I tried adding the piece of code that was suggested but still get the error. I checked and there is nothing else in the before update event so I'm not sure where to go next. I'm attaching the stripped down version of the database.
    Thanks,
    Leesha

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

    Re: Close Action Canceled (2002)

    The code in tne Before Update event interferes with the On Click code of (for example) the Save Record button and the Close Form button. If you want to avoid conflicts, the two best solutions would be

    a) Remove the Form_BeforeUpdate code entirely.

    or

    [img]/forums/images/smilies/cool.gif[/img] Make frmPatientDemographics an unbound form, and save the record in code when the user has confirmed it.

    If you don't want to do either, you'll have to build error handlers into the event procedures that ignore error 2501 (action canceled):

    Private Sub cmdSaveRecord_Click()
    On Error GoTo ErrHandler
    'Saves Record
    DoCmd.RunCommand acCmdSaveRecord
    Exit Sub
    ErrHandler:
    If Not Err = 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error GoTo ErrHandler
    'Asks whether record should be saved
    If MsgBox("Do you want to save this record?", vbQuestion Or vbYesNo) = vbNo Then
    Cancel = True
    Me.Undo
    End If
    Exit Sub
    ErrHandler:
    If Not Err = 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  6. #6
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close Action Canceled (2002)

    Hi,

    No wonder I couldn't figure it out! If I take out the before update code completely, how do I write the code to save the record if the form is unbound? I've never done that before.

    If I use the error handler that you wrote for me (thanks!) I'm assuming I replace the present save code with it. Do I also get rid of the before update code? I ask because I tried that and got an error.

    Thanks,
    Leesha

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

    Re: Close Action Canceled (2002)

    The code I posted was meant as replacement for the cmdSaveRecord_Click and Form_BeforeUpdate event procedures. What error did you get?

    Making the form unbound means that the record source of the form is blank, and the control source of the text boxes too. You'd have to use DAO or ADO code to open a recordset on the table and save the values. This is a lot of work, but in some situations it's the best solution because you only save a record when you (as developer) want to, not when Access decides it would be a good idea.

  8. #8
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close Action Canceled (2002)

    Hi Hans,

    I don't know where you find the patience. I went back and looked at what I did and I pasted the code all into the save_click event and didn't break it out. Daaaaaaaaaaa, long day. Anyway it works just fine now that I have my head screwed on and slowed down long enough to look at the code!

    Thanks,
    Leesha

Posting Permissions

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