Hello to all forum friends,
I would like to ask if there is a way so that using vba code to be able to closed any opened form in my database. I would appreciate if someone could enlighten me.
Thank you in advance
Hello to all forum friends,
I would like to ask if there is a way so that using vba code to be able to closed any opened form in my database. I would appreciate if someone could enlighten me.
Thank you in advance
This function will close all forms with save.
Code:Function CloseAllForms() Dim obj As AccessObject, dbs As Object Set dbs = Application.CurrentProject ' Search for open AccessObject objects in AllForms collection. For Each obj In dbs.AllForms If obj.IsLoaded = True Then DoCmd.Close acForm, obj.Name, acSaveYes ' Print name of obj. Debug.Print obj.Name End If Next obj End Function
The acSaveYes parameter has nothing to do with saving records, it is to save design changes.
Record edits are committed to table when form closes, move to another record, or run acCmdSaveRecord command.
Alternatively, try: DoCmd.RunCommand acCmdCloseAll
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Its not used for records it used to prevent save changes dialog from popping up. Which can be omitted if you choose. What is the relavence of move to another record or acCmdSaveRecord to the above code. You could use
DoCmd.RunCommand acCmdCloseAll
it you desire to close all open objects.
Good point, but it will only popup if there were changes to properties. acSaveNo would accomplish the same and is more reassuring to me than acSaveYes, even though I know changes can only be saved from design view.
The suggested code will close all objects, not the db itself.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I know that but the question was to close forms I had to assume that was all they wanted closed. The best way I know to accomplish this is iterating through the database object.
Just offering user options to consider.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Dear all,
I would like to thank you very much for your help. One thing more if you can suggest a solution. How can write the code in order to close all active forms excepts the switchboard?
Thanks again all of you
Include another nested If. Is Switchboard the name of form?
If obj.Name <> "Switchboard" Then
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
June7,
The name of my switchboard form is "frmSwitchboard". I' ll try the suggested code line to see whats happened.
Thanks a lot