Results 1 to 4 of 4
  1. #1
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30

    Close a Form and Subform without saving either

    This would seem to be simple, but i have looked for an answer that works and haven't come up with anything. Here is the setup.

    I have a keyword search box and command button on the main form to filter the subform, along with a save and cancel button. The goal is for any employee to search an order using the search function and make an edit on the subform when necessary, then save it and close the form. However, if an unwanted change is made and the cancel button is hit, the changes are still saved. The dirty function works fine controlling the main form with undo in the code, but they do not translate to anything done on the subform. Below is my code for canceling and closing information on main forms. Can someone help me fix this to also affect the subform?

    If Me.Dirty = True Then


    DoCmd.RunCommand acCmdUndo
    DoCmd.Close acForm, Me.Name
    Else
    DoCmd.Close acForm, Me.Name
    End If

    Thanks,

    Garret

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    When you move from the Subform to the Main Form (where your buttons are, if I read this correctly,) the Subform Form Record is automatically saved...that's how Access works. You need your Save/Dump buttons on the Subform, if it's Subform Records you're dealing with.

    You can't have Command Buttons on Datasheet View Forms, as most Subforms are displayed, and the usual approach is to have the Subform in Continuous View, which can have Command Buttons, tweaked to look like a Datasheet View Form, if that's your preference.

    Linq ;0)>

  3. #3
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30
    Quote Originally Posted by Missinglinq View Post
    When you move from the Subform to the Main Form (where your buttons are, if I read this correctly,) the Subform Form Record is automatically saved...that's how Access works. You need your Save/Dump buttons on the Subform, if it's Subform Records you're dealing with.

    You can't have Command Buttons on Datasheet View Forms, as most Subforms are displayed, and the usual approach is to have the Subform in Continuous View, which can have Command Buttons, tweaked to look like a Datasheet View Form, if that's your preference.

    Linq ;0)>
    Thanks for the confirmation. That was what I was thinking, but I really hoped there was a VBA solution to it.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    but I really hoped there was a VBA solution to it.
    investigate begintrans, committrans - might do what you want

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

Similar Threads

  1. Replies: 2
    Last Post: 11-18-2014, 09:12 AM
  2. Replies: 1
    Last Post: 07-22-2011, 02:48 PM
  3. Replies: 6
    Last Post: 04-13-2011, 03:55 PM
  4. Replies: 2
    Last Post: 01-29-2010, 11:33 AM
  5. Unable to close Query without saving
    By jhrBanker in forum Access
    Replies: 0
    Last Post: 06-08-2009, 05:09 PM

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