Results 1 to 5 of 5
  1. #1
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117

    Canceling out of a form

    So, I have options on some of my data forms where I can cancel out of making the entry and return to the previous form.



    My code for that is basically this format

    Code:
    Private Sub Command_Cancel_Exit_Click()  'Removes any changes or entries and returns to the Inspection Log
    
        If (Forms!F_Log_Inspection_Apiary_Entry_Edit.Dirty = -1) Then
        
            DoCmd.RunCommand acCmdUndo
            
        End If
        
        DoCmd.Close acForm, "F_Log_Inspection_Apiary_Entry_Edit"
        Forms!F_Log_Inspection_Main.Visible = True
        DoCmd.Requery
    
    
    End Sub
    My question of the day is, if I have one or more subforms within the form, do I need to check Dirty for each subform as well as the main form or does the one condition cover everything ?

    Reason I am asking is I am having trouble canceling out of a form with multiple subforms and I'm trying to narrow down possible causes.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Each form is a separate object.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    If you're editing a subform and you move off of it, chances are quite good that it's no longer dirty - you just saved the record. So checking for dirty can return False, yet you edited a record you may not have wanted to edit. Sometimes, the only way around this is to use unbound forms or what I call staging tables. In the latter case these tables may be exact dupes of the primary table except they cannot have an autonumber field (or at least that would be useless). You would have the PK values from the primary table as foreign key values though, so that you can relate the changes made back to the primary table. In the end, if the user decides to not save changes, the staging table data is flushed and the form closed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You can use any forms Before Update event to capture and back out of edits.
    This includes sub forms, but be aware that changes to the main form are saved as soon as you move to the sub form, so you would need to capture both forms updates.

    I would have a read here
    https://www.access-programmers.co.uk/forums/threads/bad-data-is-bad-for-business-1-and-2.324342/

    About how to validate and save or not save data in forms, it will save you a lot hard work further down the line.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Ok folks, after messing with this and things getting complicated, I figured out a much easier solution in this particular instance.

    I put the tables into a query and based the form on that and got rid of the sub-tables so I can easily cancel out of the form and undo if any part of the form is dirty.

    Underwhelming I know but it works for this application at least.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-18-2020, 12:46 PM
  2. Replies: 4
    Last Post: 11-08-2016, 07:49 PM
  3. Replies: 4
    Last Post: 10-10-2015, 05:09 PM
  4. Out Damn Detail, Out I Say
    By libraccess in forum Reports
    Replies: 5
    Last Post: 02-19-2013, 12:46 AM
  5. Canceling a report filter without Run-time error
    By Monterey_Manzer in forum Forms
    Replies: 3
    Last Post: 12-03-2012, 03:28 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