Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    26

    Unanswered: Close form and don't save error

    Hi all,

    I am trying to create a close button where if the current data on the screen has not been saved, a message box would appear asking if the user would like to save the data. If they click yes, then the data would be saved, and if they clicked no, the data they just entered would be deleted. I have some code, but its not working correctly. If I click yes everything is fine, but if i click no, I get a run-time error 2467. It says the error is with "me.undo" but I don't know what I'm doing wrong. Any incite would help, thanks.

    Code:
    Private Sub Command37_Click()
    Dim comdirty As String
    If Me.Dirty = True Then GoTo comdirty
    DoCmd.OpenForm "navigation1"
    DoCmd.Close acForm, "demographicsnewperson"
    Exit Sub
    comdirty: comdirty = MsgBox("Would you like to save changes?", vbYesNo, "SAVE CHANGES")
    If comdirty = vbYes Then Me.Dirty = False
    DoCmd.OpenForm "navigation1"
    DoCmd.Close acForm, "demographicsnewperson"
    If comdirty = vbNo Then
    Me.Undo
    DoCmd.OpenForm "navigation1"
    DoCmd.Close acForm, "demographicsnewperson"
    End If
    End Sub

  2. #2
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    I never make a CLOSE BUTTON on the form. Tehre is a
    smal button (X) on the right corner (on the form).
    Click on this button for close form.
    Look at "DemoSaveA2000.mdb" (attachment, zip).
    Open Form1 and try. Look at VBA.
    Attached Files Attached Files

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Awesome, thank you very much, it finally works!

Posting Permissions

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