jsttricklin
I have an automated archive process that runs daily in order to keep my site dbs table records as small as possible. Though, I don't create a db for each of the sites, instead, I pull data from each of the site dbs and archive them into one central archive db. Therefore, I created the archive db with the apportriate tables (one for each site) and loop through the process to extract the needed data. My code is quite lengthly and will probably be hard to read here. copy the contents of the code into a blank module an it should be easier to read. I hope this will point you in the righ direction.
code:
Option Base 1
Option Compare Database
Option Explicit
Dim archiveDbTableType(10) As String, tobeArchivedDbTableType(10) As String, errTag As Boolean, _
errCount As Byte, opCode As Byte
Public Function moveArchiveData()
On Error GoTo Err_moveArchiveData
Dim archiveDbTable As TableDef, archiveDbName As String, tblTypeID As Byte, _
archiveDb As Database, DBFileID As Byte, DBFilePathID As Byte
DoCmd.Hourglass True
'Open error log
Open "c:\temp\archErr.log" For Output As #1
'Open archive db
Set archiveDb = OpenDatabase(DBLocations(4, 0))
'Set path id in relation to file location module
DBFilePathID = 0
'Set data to table type array
setTableTypes
archiveDbName = ("'" & archiveDb.Name & "'"

errCount = 0
'Loop through all deposit balancing dbs and archive data
For DBFileID = 5 To 14
Dim archiveDbTableName As String, tobeArchivedDb As Database, _
tobeArchivedDbTable As TableDef, tobeArchivedDbName As String, tobeArchivedDbTableName As String, _
tobeArchivedDbDateFieldName As String, tobeArchivedDbClearedFieldName As String, _
sqlCondition As String, sqlStatement As String
errTag = False
opCode = 0
tblTypeID = DBFileID - 4
Set archiveDbTable = archiveDb.TableDefs("tblReconPstngs_" & archiveDbTableType(tblTypeID))
Set tobeArchivedDb = OpenDatabase(DBLocations(DBFileID, DBFilePathID))
Set tobeArchivedDbTable = tobeArchivedDb.TableDefs(tobeArchivedDbTableType(tblTypeID))
archiveDbTableName = archiveDbTable.Name
tobeArchivedDbName = ("'" & tobeArchivedDb.Name & "'"

tobeArchivedDbTableName = ("[" & tobeArchivedDbTable.Name & "]"
Select Case DBFileID
'Set Non-Centralized specific table fields
Case 5, 8, 13, 14
tobeArchivedDbDateFieldName = "[Pst Date]"
tobeArchivedDbClearedFieldName = "Cleared"
'Set Centralized specific table fields
Case Else
tobeArchivedDbDateFieldName = "Date"
tobeArchivedDbClearedFieldName = "Status"
End Select
'Set sql specific WHERE statement in relation to specific table fields
sqlCondition = ("WHERE " & tobeArchivedDbDateFieldName & " <= Date() - 95 " _
& "AND " & tobeArchivedDbClearedFieldName & " = Yes"
If errTag = False Then
opCode = 1
'Move archivable data from deposit balancing db to archive db
DoCmd.RunSQL ("INSERT INTO " & archiveDbTableName & " IN " & archiveDbName & " " _
& "SELECT * FROM " & tobeArchivedDbTableName & " IN " & tobeArchivedDbName & " " _
& sqlCondition & ";"

End If
If errTag = False Then
opCode = 2
'Delete archived data from deposit balancing db
DoCmd.RunSQL ("DELETE * FROM " & tobeArchivedDbTableName & " IN " & tobeArchivedDbName & " " & sqlCondition & ";"

End If
'Close deposit balancing db
tobeArchivedDb.Close
'Next deposit balancing db to be archived
Next DBFileID
opCode = 3
'Set archival process completion data
With archiveDb
Dim lastArchive As Recordset
Set archiveDbTable = .TableDefs("lastArchDate"

With archiveDbTable
Set lastArchive = .OpenRecordset(dbOpenTable)
'Write success/fail codes to lastArchived table
With lastArchive
.MoveFirst
.Edit
!lastArchived = DATE
If errCount = 0 Then
!lastStatus = "Successful"
Else
!lastStatus = ("Failed " & errCount)
End If
.Update
.Close
End With
End With
'Close archive db
.Close
End With
Close #1 'Close error log
DoCmd.Hourglass False
Beep
MsgBox "Data archived.", vbInformation, varStorage.appName
Exit_moveArchiveData:
Exit Function
Err_moveArchiveData:
'Write error to log and continue
errTag = True
errCount = errCount + 1
Write #1, DBFileID; opCode; Err.DESCRIPTION
Resume Next
End Function
Private Sub setTableTypes()
'set archiveDb table name in reference to tobeArchivedDb database
archiveDbTableType(1) = "Dime" 'for use with archiveDb linked to DmRcnV2 table
archiveDbTableType(2) = "ElSeg" 'for use with archiveDb linked to ESGrp1V2 table
archiveDbTableType(3) = "ElSeg" 'for use with archiveDb linked to ESGrp2v2 table
archiveDbTableType(4) = "Ga" 'for use with archiveDb linked to GaRcnV2 table
archiveDbTableType(5) = "Pomp" 'for use with archiveDb linked to PompVer2 table
archiveDbTableType(6) = "Port" 'for use with archiveDb linked to PortVer2 table
archiveDbTableType(7) = "SnLe" 'for use with archiveDb linked to SanLVer2 table
archiveDbTableType(8) = "Taco" 'for use with archiveDb linked to TacoVer2 table
archiveDbTableType(9) = "Tx" 'for use with archiveDb linked to TxRcnV2 table
archiveDbTableType(10) = "Co" 'for use with archiveDb linked to CoRcnV2 table
'set tobeArchivedDb table name in reference to archiveDb database
tobeArchivedDbTableType(1) = "tblReconPstngs" 'for use with linked DmRcnV2 table
tobeArchivedDbTableType(2) = "11720 El Segundo" 'for use with linked ESGrp1V2 table
tobeArchivedDbTableType(3) = "11720 El Segundo" 'for use with linked ESGrp2v2 table
tobeArchivedDbTableType(4) = "tblReconPstngs" 'for use with linked GaRcnV2 table
tobeArchivedDbTableType(5) = "11720 Pompano" 'for use with linked PompVer2 table
tobeArchivedDbTableType(6) = "11720 Portland" 'for use with linked PortVer2 table
tobeArchivedDbTableType(7) = "11720 San Leandro" 'for use with linked SanLVer2 table
tobeArchivedDbTableType(8) = "11720 Tacoma" 'for use with linked TacoVer2 table
tobeArchivedDbTableType(9) = "tblReconPstngs" 'for use with linked TxRcnV2 table
tobeArchivedDbTableType(10) = "tblReconPstngs" 'for use with linked CoRcnV2 table
End Sub
Hope this helps
ERM