A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Delete all modules but 1



 
 
Thread Tools Display Modes
  #1  
Old July 9th, 2008, 10:18 PM posted to microsoft.public.access.queries
auujxa2 via AccessMonster.com
external usenet poster
 
Posts: 118
Default Delete all modules but 1

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

--
Laser

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200807/1

  #2  
Old July 10th, 2008, 12:24 AM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Delete all modules but 1

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
'================================================= ===


auujxa2 via AccessMonster.com wrote:
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

  #3  
Old July 10th, 2008, 12:41 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Delete all modules but 1

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

John Spencer wrote:
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
'================================================= ===


auujxa2 via AccessMonster.com wrote:
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

  #4  
Old July 10th, 2008, 02:52 PM posted to microsoft.public.access.queries
auujxa2 via AccessMonster.com
external usenet poster
 
Posts: 118
Default Delete all modules but 1

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 Spencer wrote:
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


--
Laser

Message posted via http://www.accessmonster.com

  #5  
Old July 10th, 2008, 02:57 PM posted to microsoft.public.access.queries
auujxa2 via AccessMonster.com
external usenet poster
 
Posts: 118
Default Delete all modules but 1

Got it. I did a macro "RunCode" and put the ImportDb("C:\pathname\
MySourceDatabase.mdb") there

auujxa2 wrote:
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]
DoCmd.DeleteObject acMacro, strDocName
DoCmd.DeleteObject acReport, strDocName



--
Laser

Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:28 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.