Just a slight enhancement to MajP's code:
Public Sub test()
On Error Resume Next
Dim frm As AccessObject
Dim ctrl As Access.Control
Dim frmOpen as Form
Dim blnClose As Boolean
For Each frm In CurrentProject.AllForms
Set frmOpen=Forms(frm.Name)
blnClose=(Err.Number<>0)
Err.Clear
If blnClose Then
DoCmd.OpenForm frm.Name, acNormal, , "0=1", , acHidden
End If
For Each ctrl In Forms(frm.Name)
Debug.Print ctrl.Name
Next ctrl
If blnClose Then
DoCmd.Close acForm, frm.Name
End If
set frmOpen=Nothing
Next frm
End Sub
The differences:
- acDesign cannot be used in MDE, so open the form in normal view, but hidden
- If the form has a data source, filter it so that no records are returned (0=1)
- close only the forms that were opened by the procedure
![[pipe] [pipe] [pipe]](/data/assets/smilies/pipe.gif)
Daniel Vlas
Systems Consultant