Getting rid of unused subforms

  • Thread starter Thread starter dabeck
  • Start date Start date
D

dabeck

While "creating" forms I often end up with xyz subform1, xyz subform2, etc
is there an easy way to see if a particular version of a subform is "being
used" as part of a form?
 
While "creating" forms I often end up with xyz subform1, xyz subform2, etc
is there an easy way to see if a particular version of a subform is "being
used" as part of a form?

postscript I forgot to add...

A tedious but free method is to rename each subform in turn (say to
[xyz subform2_X] ), and open all your production forms. If you get an
error you can just rename the subform back; if not, delete it.
 
John Vinson said:
While "creating" forms I often end up with xyz subform1, xyz subform2, etc
is there an easy way to see if a particular version of a subform is "being
used" as part of a form?

postscript I forgot to add...

A tedious but free method is to rename each subform in turn (say to
[xyz subform2_X] ), and open all your production forms. If you get an
error you can just rename the subform back; if not, delete it.

The following code will list all subform controls (and the form they point
to) on all forms:

Sub FindSubforms()
Dim dbCurr As DAO.Database
Dim conForms As DAO.Container
Dim docCurr As DAO.Document
Dim ctlCurr As Control
Dim frmCurr As Form
Dim intLoop As Integer

DoCmd.Hourglass True

Set dbCurr = CurrentDb()
Set conForms = dbCurr.Containers!Forms
With conForms
For Each docCurr In .Documents
DoCmd.OpenForm docCurr.Name, acDesign, , , acFormReadOnly,
acHidden
Set frmCurr = Forms(docCurr.Name)
For Each ctlCurr In frmCurr.Controls
If ctlCurr.ControlType = acSubform Then
Debug.Print frmCurr.Name & " contains " & ctlCurr.Name &
_
" which uses subform " & ctlCurr.SourceObject
End If
Next ctlCurr
DoCmd.Close acForm, frmCurr.Name, acSaveNo
Next docCurr
End With

Set ctlCurr = Nothing
Set frmCurr = Nothing
Set docCurr = Nothing
Set conForms = Nothing
Set dbCurr = Nothing

DoCmd.Hourglass False

End Sub
 
Very Nice! :-)

Ron W
Douglas J. Steele said:
John Vinson said:
While "creating" forms I often end up with xyz subform1, xyz subform2, etc
is there an easy way to see if a particular version of a subform is "being
used" as part of a form?

postscript I forgot to add...

A tedious but free method is to rename each subform in turn (say to
[xyz subform2_X] ), and open all your production forms. If you get an
error you can just rename the subform back; if not, delete it.

The following code will list all subform controls (and the form they point
to) on all forms:

Sub FindSubforms()
Dim dbCurr As DAO.Database
Dim conForms As DAO.Container
Dim docCurr As DAO.Document
Dim ctlCurr As Control
Dim frmCurr As Form
Dim intLoop As Integer

DoCmd.Hourglass True

Set dbCurr = CurrentDb()
Set conForms = dbCurr.Containers!Forms
With conForms
For Each docCurr In .Documents
DoCmd.OpenForm docCurr.Name, acDesign, , , acFormReadOnly,
acHidden
Set frmCurr = Forms(docCurr.Name)
For Each ctlCurr In frmCurr.Controls
If ctlCurr.ControlType = acSubform Then
Debug.Print frmCurr.Name & " contains " & ctlCurr.Name &
_
" which uses subform " & ctlCurr.SourceObject
End If
Next ctlCurr
DoCmd.Close acForm, frmCurr.Name, acSaveNo
Next docCurr
End With

Set ctlCurr = Nothing
Set frmCurr = Nothing
Set docCurr = Nothing
Set conForms = Nothing
Set dbCurr = Nothing

DoCmd.Hourglass False

End Sub
 
Back
Top