Delete all modules but 1

  • Thread starter auujxa2 via AccessMonster.com
  • Start date
A

auujxa2 via AccessMonster.com

Here is code I have that deletes all queries, forms, and reports. The last
part I want to delete all modules but one. Any ideas? Case 4 is modules,
and the last line of the code is where I think the code I'm asking for should
go. Just don't know how to word it.

Thank YOu in advance

Dim db As Database 'Database to import
Dim strTDef As String 'Name of table or query to import
Dim qd As QueryDef 'Querydefs in db
Dim doc As Document 'Documents in db
Dim strCntName As String 'Document container name
Dim X As Integer 'For looping
Dim cntContainer As Container 'Containers in db
Dim strDocName As String 'Name of document
Dim intConst As Integer
Dim cdb As Database 'Current Database
Dim rel As Relation 'Relation to copy
Dim nrel As Relation 'Relation to create
Dim strRName As String 'Copied relation's name
Dim strTName As String 'Relation Table name
Dim strFTName As String 'Relation Foreign Table name
Dim varAtt As Variant 'Attributes of relation
Dim fld As Field 'Field(s) in relation to copy
Dim strFName As String 'Name of field to append
Dim strFFName As String 'Foreign name of field to append

'Open database which contains objects to import.
Set db = DBEngine.Workspaces(0).OpenDatabase(strPath, True)

'Delete all queries.

For Each qd In db.QueryDefs

strTDef = qd.Name

DoCmd.DeleteObject acQuery, strTDef

Next

'Loop through containers and delete all documents.

For X = 1 To 4

Select Case X

Case 1
strCntName = "Forms"
intConst = acForm

Case 2
strCntName = "Reports"
intConst = acReport

Case 3
strCntName = "Scripts"
intConst = acMacro

Case 4
strCntName = "Modules"
intConst = acModule

End Select

Set cntContainer = db.Containers(strCntName)

For Each doc In cntContainer.Documents

strDocName = doc.Name

DoCmd.DeleteObject acForm, strDocName
DoCmd.DeleteObject acMacro, strDocName
DoCmd.DeleteObject acReport, strDocName
 
J

John Spencer

Does that really work for you? It would seem to me that the routine is
liable to skip every other document when it is doing the delete. But
perhaps I am wrong.

IF strDocName = "name of module" and intConst = acModule then
'Skip this one
ELSE
DoCmd.DeleteObject, intConst, strDocName
END IF

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
J

John Spencer

I was wrong, it should work to delete every object.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
A

auujxa2 via AccessMonster.com

Looks good. Thank you. One last question. I have the same code to import
database objects, that is kicked off by entering code into the database
window:

?ImportDb("C:\pathname\MySourceDatabase.mdb")

and

?DeleteDb("C:\pathname\MySourceDatabase.mdb")

It returns a TRUE value to let me know it worked. But how can I kick the
import and delete modules off from a form button, instead of the code above
in the database window?

Thank you in advance.

John said:
Does that really work for you? It would seem to me that the routine is
liable to skip every other document when it is doing the delete. But
perhaps I am wrong.

IF strDocName = "name of module" and intConst = acModule then
'Skip this one
ELSE
DoCmd.DeleteObject, intConst, strDocName
END IF

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Here is code I have that deletes all queries, forms, and reports. The last
part I want to delete all modules but one. Any ideas? Case 4 is modules,
[quoted text clipped - 69 lines]
DoCmd.DeleteObject acMacro, strDocName
DoCmd.DeleteObject acReport, strDocName
 
A

auujxa2 via AccessMonster.com

Got it. I did a macro "RunCode" and put the ImportDb("C:\pathname\
MySourceDatabase.mdb") there
Looks good. Thank you. One last question. I have the same code to import
database objects, that is kicked off by entering code into the database
window:

?ImportDb("C:\pathname\MySourceDatabase.mdb")

and

?DeleteDb("C:\pathname\MySourceDatabase.mdb")

It returns a TRUE value to let me know it worked. But how can I kick the
import and delete modules off from a form button, instead of the code above
in the database window?

Thank you in advance.
Does that really work for you? It would seem to me that the routine is
liable to skip every other document when it is doing the delete. But
[quoted text clipped - 18 lines]
 

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