Getting rid of unused subforms

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?
 
J

John Vinson

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.
 
D

Douglas J. Steele

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
 
R

Ron Weiner

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top