Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting MS objects

Status
Not open for further replies.

throwdini

Technical User
Oct 20, 2000
37
US
Does anyone know how one could loop through the objects in a database, (forms, queries, modules, reports) and delete them?

When I try to use "For each frm in application.forms" it will only look at the forms that are open. (The same for reports, modules...) Any help is greatly appreciated.

Thanks,
Jay
 
This code will loop thru all the documents in the database and print their names.
You should be able to change it to delete them quite easily.

Sub LoopThruDocs()
Dim strPath As String
strPath = GetDBLocation & "txtBackup\"
Dim ctr As Container, doc As Document, intType As Integer, qd As QueryDef
For Each ctr In CurrentDb.Containers
If ctr.Name <> &quot;Databases&quot; And ctr.Name <> &quot;Relationships&quot; And ctr.Name <> &quot;scripts&quot; And ctr.Name <> &quot;SysRel&quot; Then
For Each doc In ctr.Documents
Select Case ctr.Name
Case Is = &quot;Tables&quot;
intType = acTable
Case Is = &quot;Forms&quot;
intType = acForm
Case Is = &quot;Reports&quot;
intType = acReport
Case Is = &quot;Macros&quot;
intType = acMacro
Case Is = &quot;Modules&quot;
intType = acModule
Case Else
intType = 9
End Select
If doc.Name <> &quot;Admin&quot; And left(doc.Name, 4) <> &quot;MSys&quot; Then
Debug.Print doc.Name
End If
Next doc
End If
Next ctr
End Sub

HTH

Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.pnn.police.uk
----------------------------------
 
Ben-

Thanks for the tip. I'll let you know how it works.

-Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top