我正在升级现有的前端和后端mdbs集。后端变得臃肿并影响性能。仍需要保留两年以上的数据,但实际上不可能再次访问。我的想法是,有一个活跃的后端(即,只有当前和前一年的数据)和一个存档的后端(即,在每年年初,附加来自活动的所有数据)是合适的。后端进入现有的归档后端)。
答案 0 :(得分:2)
你提到腹胀。如果您还没有,请在膨胀的后端MDB上运行Compact和Repair。除了缩小文件大小外,它还将更新索引统计信息,这可以使查询优化器更好地决定您的查询计划。
您没有提供有关现有数据库和表格的详细信息,因此我做了几个简化的假设。
因此,我建议您制作后端数据库的副本,然后尝试使用此过程。查看立即窗口以检查INSERT和DELETE语句。如果它们看起来合理,则取消注释两个CurrentDb.Execute行,看看会发生什么。 (你先做个备份吧?)
Public Sub DoArchive()
Const cstrArchive As String = "C:\db\archive.mdb"
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strAppend As String
Dim strCutoff As String
Dim strDelete As String
Dim strWhere As String
Dim strMsg As String
On Error GoTo ErrorHandler
Set db = CurrentDb
strCutoff = "#" & Year(Date) - 1 & "/01/01#"
strWhere = " WHERE date_field < " & strCutoff
For Each tdf In db.TableDefs
If Len(tdf.Connect) > 0 Then
strAppend = "INSERT INTO [" & tdf.name & "] IN '" & _
cstrArchive & "' SELECT * FROM [" & tdf.name & _
"]" & strWhere & ";"
Debug.Print strAppend
''CurrentDb.Execute strAppend, dbFailOnError
strDelete = "DELETE FROM [" & tdf.name & "]" & _
strWhere & ";"
Debug.Print strDelete
''CurrentDb.Execute strDelete, dbFailOnError
End If
Next tdf
ExitHere:
On Error GoTo 0
Set tdf = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
strMsg = "Error " & Err.Number & " (" & Err.description _
& ") in procedure DoArchive"
MsgBox strMsg
GoTo ExitHere
End Sub