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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|