Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2012
    Posts
    79

    Unanswered: Closing database, delete dirty forms.

    Hello!

    Brief overview:

    Database has multiple data entry forms. If an individual were to be working with a form, enter a little bit of information, or even leave it blank, and then close the entire database without closing the form first, it creates blank, or incomplete records in the table.

    I would like to either have a general database "closing procedure" where it closes all open dirty forms without saving the record. Or prevent the individual from closing the database without first closing the active form(s). Not sure what the best way to go about this is, so any help would be appreciated.

    Thanks!
    Version: Access 2010

  2. #2
    Join Date
    Nov 2011
    Posts
    413

    Close Dirty Forms

    You could use this module and run it via your forms with CloseForm()

    Here is the module code: Hope it helps:

    PHP Code:
    Function CloseForm()
    Dim CurrentForm As Form

    ' As form take current open form

    Set CurrentForm = Screen.ActiveForm

    You can del that error part in case you use older version of access

    On Error 
    GoTo CloseForm_Err

    ' If current form has been changed then undo changes

    If CurrentForm.Dirty Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

    I have also put code for closing current open form so It is usable for exit key on every form and before exit also requery the form

    DoCmd
    .Requery
    DoCmd
    .Close acFormCurrentForm.Name
    Else

    ' If the form is not dirty just requery and close it

    DoCmd.Requery
    DoCmd.Close acForm, CurrentForm.Name
    End If
    CloseForm_Exit:
    Exit Function

    CloseForm_Err:
    MsgBox Error$
    Resume CloseForm_Exit

    End Function 

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    In such a situation, I would use:
    Code:
    Private Function SaveAndCloseAllForms()
    
        With Application.Forms
            Do Until .Count = 0
                If .Item(0).Dirty = True Then .Item(0).Dirty = False
                DoCmd.Close acForm, .Item(0).Name
            Loop
        End With
             
    End Function
    Have a nice day!

  4. #4
    Join Date
    Nov 2012
    Posts
    79
    I've tried both of these and no joy!

    BUT! I've found the root cause as to why my forms are adding blank records in the first place. Form_Current()!

    Once I get that mess sorted out I'll come back and see if I even need these solutions. Thanks!
    Version: Access 2010

  5. #5
    Join Date
    Nov 2012
    Posts
    79
    I've managed to track down the reason why I get blank and incomplete records.

    My form has a couple of procedures that populate certain fields when the form opens. If I delete these procedures, then it doesn't save a record no matter what I do, until I hit the save record button.

    My guess is I have to make these fields null on unload. Or delete the record somehow.

    *shrugs*
    Version: Access 2010

Posting Permissions

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