4

在我处理这个数据库应用程序的过程中,我显然设法破坏了应用程序中的一个表单 - 尝试将任何编辑保存到表单上的任何字段都会导致 Access 崩溃,并且当 Access 尝试时数据库文件报告损坏重新打开它。

我尝试将整个表单 + 控件导出为文本,然后使用 VB 代码(来自 Allen Browne 的网站)重新导入它们,但它不会重新导入而不会导致 Access 崩溃或告诉我表单无法导入到一个错误(没有给出错误编号或描述)。

表格比较复杂,所以我很犹豫是否从头开始重新制作,那么有没有办法保存它?如果我设法恢复它,这是否意味着我应该将所有内容转移到一个新的 MDB 文件中(以防它是级联故障效应)?

老实说,我以前从未设法破坏 Access 数据库对象,所以我不知道这是否标志着该 MDB 文件的结束,或者只是我可以纠正并像以前一样继续的事情。

4

6 回答 6

3

一旦你制作了数据库的副本,反编译是一件好事。您是否尝试过使用“文件”>>“另存为”以不同的名称保存表单?还可以尝试从数据库窗口复制和粘贴具有不同名称的表单。

此外,我的经验是,一份损坏的表格/报告不会传播到数据库的其余部分。也就是说,清理东西并没有什么坏处。压缩和修复仅修复表和相关数据,例如索引和关系。要清理损坏的其他对象,例如表单和报表,您必须将它们导入新的 MDB/ACCDB。提示:如果您有很多对象,请关闭数据库容器窗口。Access 在导入刷新数据库容器窗口期间浪费了大量时间。

于 2009-08-24T22:38:51.693 回答
3

我最终不得不做的是重新创建表单,并逐个元素地复制,直到我发现 strSupplierID 组合框本身就是导致崩溃的原因。我从头开始重新创建它,手动为其赋予相同的属性,并从我剪切并粘贴到剪贴板的存储副本中替换 VB。表单现在可以工作了,我删除了损坏的表单,并压缩了数据库。谢谢大家的帮助!:)

于 2009-08-28T19:04:55.977 回答
2

其他人为您提供了各种可能恢复损坏的表格的方法。有时,承载代码的 Access 对象将变得不可挽回地损坏,并且这些方法都不起作用。在这种情况下,您必须查看备份以找到一个未损坏的版本作为起点并导入该版本,然后将其修改回对象的当前状态。

我发布了一个答案,建议如果您在代码承载对象中遇到损坏,您可能需要更改您的编码实践。

  1. 首先,您需要确保定期备份并且不要覆盖它们。回滚到早期版本始终是最后的手段。

  2. 始终关闭 VBE 选项中的 COMPILE ON DEMAND。阅读 Michael Kaplan关于反编译开关的真实交易的文章以了解原因。

  3. 在 VBE 中,将编译按钮(和调用堆栈按钮)添加到您的常规 VBE 工具栏,并在每几行代码后点击该编译按钮,然后保存您的代码。

  4. 确定一个合理的时间间隔来备份和反编译您的应用程序。如果您正在执行繁重的代码冲击,您可能希望每天都这样做。如果您在编码过程中遇到 Access 崩溃,您可能需要进行备份和反编译/重新编译。当然,在分发给用户之前,您应该反编译并重新编译您的应用程序。

如果您遵循这些做法,将尽可能减少导致代码承载 Access 对象损坏的原因,同时您还将拥有大量备份(多级冗余备份是必须的,因为当备份失败时,它们几乎总是通过多个级别级联-具有多种类型的备份并且不依赖于自动备份)。

但关键点:

经常编译,经常反编译,讨厌的东西永远不会有机会在你的应用程序的 p 代码中积累。

于 2009-08-25T20:12:11.310 回答
0

您是否看过 Allen Browne 处理腐败的全套方法:http: //allenbrowne.com/ser-47.html?特别是反编译。

可能值得尝试将控件复制并粘贴到新表单中,然后逐渐添加回代码中。

于 2009-08-24T19:59:37.567 回答
0

我曾多次遇到过这种情况。这里有几件事拯救了我的培根。我假设您使用的是 Access 2003 或更高版本。尝试将数据库转换为 Access 2002 或 2000 格式。然后将该数据库转换回您当前的版本。

这是我在以前的版本中为对抗臃肿而创建的一些代码。它也为我解决了这个问题 95% 的时间。

选项比较数据库选项显式

Private Sub cmdCreateDuplicate_Click()
'********************************************************
' Author        Daniel Tweddell
' Revision Date 10/27/05
'
' To Combat bloat, we are recreating the a new database
'********************************************************
On Error GoTo Err_Function
    Dim strNewdb As String
    Dim AppNewDb As New Access.Application 'the new database we're creating to manage the updates
    strNewdb = CurrentProject.Path & "\db1.mdb"
    SysCmd acSysCmdSetStatus, "Creating Database. . ."
    With AppNewDb
        DeleteFile strNewdb 'make sure it's not already there
        .Visible = False 'hear no database see no database
        .NewCurrentDatabase strNewdb 'open it
        ChangeRemoteProperty "StartupShowDbWindow", AppNewDb, , dbBoolean, False
        ChangeRemoteProperty "Auto compact", AppNewDb, , dbBoolean, True
        ImportReferences AppNewDb, Application
        .CloseCurrentDatabase
    End With
    Set AppNewDb = Nothing
    Dim ao As AccessObject
    For Each ao In CurrentData.AllTables
        If Left(ao.Name, 4) <> "msys" Then
            DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acTable, ao.Name, ao.Name
            SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
        End If
    Next
    For Each ao In CurrentData.AllQueries
        DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acQuery, ao.Name, ao.Name
        SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
    Next
    For Each ao In CurrentProject.AllForms
        DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acForm, ao.Name, ao.Name
        SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
    Next
    For Each ao In CurrentProject.AllReports
        DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acReport, ao.Name, ao.Name
        SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
    Next
    For Each ao In CurrentProject.AllMacros
        DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acMacro, ao.Name, ao.Name
        SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
    Next
    For Each ao In CurrentProject.AllModules
        DoCmd.TransferDatabase acExport, "Microsoft Access", strNewdb, acModule, ao.Name, ao.Name
        SysCmd acSysCmdSetStatus, "Exporting " & ao.Name & ". . ."
    Next
    MsgBox "Creation Complete!" & vbCrLf & "Reset Password", vbExclamation, "New Database"
Exit Sub
Err_Function:
    ErrHandler Err.Number, Err.Description, Me.Name & " cmdCreateDuplicate_Click()"
End Sub


Function DeleteFile(ByVal strPathAndFile As String) As Boolean
'***********************************************************************************
' Author        Daniel Tweddell
' Revision Date 04/14/03
'
' Deletes a file
'***********************************************************************************
On Error GoTo Err_Function
    DeleteFile = True                   'default to true
    If UncDir(strPathAndFile) <> "" Then   'make sure the file is there
        Kill strPathAndFile             'delete a file
    End If
Exit Function
Err_Function:
    ErrHandler Err.Number, Err.Description, "DeleteFile()", bSilent
    DeleteFile = False                  'if there is a problem, false
End Function

Public Sub ChangeRemoteProperty(strPropName As String, _
                                appToDB As Access.Application, Optional appFromDB As Access.Application, _
                                Optional vPropType As Variant, Optional vPropValue As Variant)
'********************************************************************************
' Author        Daniel Tweddell
' Revision Date 01/13/04
'
' Changes/adds a database property in one db to match another
'********************************************************************************
On Error GoTo Err_Function
    Dim ToDB As DAO.Database
    Dim FromDB As DAO.Database
    Dim prpTest As DAO.Property
    Dim bPropertyExists As Boolean
    Set ToDB = appToDB.CurrentDb
    If Not appFromDB Is Nothing Then Set FromDB = appFromDB.CurrentDb
    bPropertyExists = False 'flag to see if we found the property
    For Each prpTest In ToDB.Properties 'first see if the property exists so we don't error
        If prpTest.Name = strPropName Then
            If IsMissing(vPropValue) Then vPropValue = FromDB.Properties(strPropName) 'in case we want to assign it a specific value
            ToDB.Properties(strPropName) = vPropValue 'if it does set it and get out or the loop
            bPropertyExists = True
            Exit For
        End If
    Next
    If Not bPropertyExists Then ' Property not found.
        Dim prpChange As DAO.Property
        If IsMissing(vPropValue) Then
            With FromDB.Properties(strPropName)
                vPropValue = .Value 'in case we want to assign it a specific value
                vPropType = .Type
            End With
        End If
        Set prpChange = ToDB.CreateProperty(strPropName, vPropType, vPropValue) 'add it
        ToDB.Properties.Append prpChange
    End If
Exit Sub
Err_Function:
    ErrHandler Err.Number, Err.Description, "ChangeRemoteProperty()", bSilent
End Sub

Public Sub ImportReferences(AppNewDb As Access.Application, appUpdateDB As Access.Application, Optional iStatus As Integer)
'********************************************************************************
' Author        Daniel Tweddell
' Revision Date 01/13/04
'
' Copies the current references from the one database to another we're building
'********************************************************************************
On Error GoTo Err_Function
    Dim rNewRef As Reference
    Dim rUpdateRef As Reference
    Dim bReferenceExists As Boolean
    Dim rToAdd As Reference
    Dim sReference As String
    If iStatus <> 0 Then ProgressBarUpdate iStatus, "Referencing Visual Basic Libraries. . ."
    For Each rUpdateRef In appUpdateDB.References
        bReferenceExists = False
        For Each rNewRef In AppNewDb.References
            sReference = rNewRef.Name
            If rUpdateRef.Name = sReference Then
                bReferenceExists = True
                Exit For
            End If
        Next
        If Not bReferenceExists Then
            With rUpdateRef
                Set rToAdd = AppNewDb.References.AddFromGuid(.Guid, .Major, .Minor)
            End With
        End If
    Next
Exit Sub
Err_Function:
    ErrHandler Err.Number, Err.Description, "ImportReferences(" & sReference & ")", bSilent
    Resume Next
End Sub
于 2009-08-25T17:14:14.383 回答
0

I have found that combo boxes with 10 or more columns can cause an Access form to corrupt. Try reducing the number of the columns or removing that combo box to see if the form saves properly. This problem is was related to working in Win 7 64 bit operating system with Access 2003 databases. There was no problem when developing in XP in other words the forms save fine with large column counts in combo boxes. Hope this information helps since it caused a lot of wasted time thinking the database was corrupted.

于 2015-11-29T16:14:14.603 回答