Results 1 to 4 of 4
  1. #1
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65

    Post Access Form- Save/Close Button error

    On a data entry form, I have a "Close" button (cmdClose) that, upon clicking, will ask if the user would like to save or discard the changes.

    This is fine, except if the user has accidentally opened the form and would like to close it. When the form is opened, unchanged, and then the Close button is clicked- The message box comes up and asks if the user would like to save the changes. Of course, there are no changes, so the user would click "No".



    Unfortunately, this causes an error "The command or action 'Undo' isn't available now."

    Is there some sort of way to add a command that says 'don't ask if the form didn't get dirty' or suppress this one error message?

    Here is my code for this button:


    Code:
    Private Sub cmdClose_Click()
    On Error GoTo Err_cmdClose_Click
        Dim stDocName As String
        Dim stMsg As String
        
        strMsg = "Do you wish to save the changes?"
        strMsg = strMsg & vbNewLine & "Click 'Yes' to save changes or 'No' to discard changes."
        
        If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Changes?") = vbYes Then 'do nothing
        Else
        DoCmd.RunCommand acCmdUndo
        End If
        
        DoCmd.Close
        stDocName = "Frm00_MainMenu"
        DoCmd.OpenForm stDocName
    
    Exit_cmdClose_Click:
        Exit Sub
    
    Err_cmdClose_Click:
       MsgBox Err.Description
       Resume Exit_cmdClose_Click
    End Sub
    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can test with:

    If Me.Dirty Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65
    Ahh! So simple! Thank you!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Disable master form close button
    By Carpy01 in forum Forms
    Replies: 3
    Last Post: 12-31-2010, 05:41 PM
  2. form won't save and close
    By Philislost in forum Access
    Replies: 6
    Last Post: 10-08-2010, 01:47 PM
  3. VB coding for saving when click on save button in form
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-04-2010, 11:11 PM
  4. Replies: 2
    Last Post: 01-29-2010, 11:33 AM
  5. Replies: 4
    Last Post: 09-10-2009, 03:09 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