访问 2013,在 LoadfromText for forms 期间出现错误 2128

Access 2013, error 2128 during LoadfromText for forms

我正在使用来自 here 的代码。经过一些小的修改。这 运行 在 Access 2016 中没问题,但在使用 Access 2013 导入期间会导致错误,该数据库将在理想情况下需要使用 2010 和 2013。

我使用 Access 2013(32 位)创建了一个虚拟机。我有 运行 有修改和没有修改的分解和组合代码,并得到相同的错误。我还将文件类型从 mdb 更改为 accdb,因为这被认为是 Access 2013 失败的原因。

我试过将2016版本保存到2003 mdb。 运行 import/export 并且它根本不起作用。然后在 access 2013 中打开 mdb 并将其保存为 accdb 并返回相同的 2128 错误。

这是 export/decompose 代码的当前版本。目的是删除 2016 年至 2013 年不兼容的行。

Option Explicit

const acForm = 2
const acModule = 5
const acMacro = 4
const acReport = 3
Const acQuery = 1
Const acExportTable = 0

' BEGIN CODE
Dim fso, relDoc
Dim sExportpath
Dim sExpModules
dim sADPFilename
Set fso = CreateObject("Scripting.FileSystemObject")
Set relDoc = CreateObject("Microsoft.XMLDOM")


If (WScript.Arguments.Count = 0) then
    MsgBox "Please supply an Access DB Name!", vbExclamation, "Error"
    Wscript.Quit()
End if
sADPFilename = fso.GetAbsolutePathName(WScript.Arguments(0))

If (WScript.Arguments.Count > 1) then
  sExpModules = WScript.Arguments(1)
  If Ucase(sExpModules) = "ALL" then
    sExpModules = ""

  End If
Else 
  sExpModules = ""
End If

sExportpath = ""

exportModulesTxt sADPFilename, UCase(sExpModules)

If (Err <> 0) and (Err.Description <> NULL) Then
    MsgBox Err.Description, vbExclamation, "Error"
    Err.Clear
End If

Function exportModulesTxt(sADPFilename, sExpModules)
    Dim myComponent
    Dim sModuleType
    Dim sTempname
    Dim sOutstring
    dim myType, myName, myPath, sStubADPFilename

    myType = fso.GetExtensionName(sADPFilename)
    myName = fso.GetBaseName(sADPFilename)
    myPath = fso.GetParentFolderName(sADPFilename)

    sExportpath = myPath & "\Source\"
    sStubADPFilename = sExportpath & myName & "_stub." & myType

    WScript.Echo "copy stub to " & sStubADPFilename & "..."
    On Error Resume Next
        fso.CreateFolder(sExportpath)
    On Error Goto 0
    fso.CopyFile sADPFilename, sStubADPFilename

    WScript.Echo "starting Access..."
    Dim oApplication
    Set oApplication = CreateObject("Access.Application")
    WScript.Echo "opening " & sStubADPFilename & " ..."
    If (Right(sStubADPFilename,4) = ".adp") Then
        oApplication.OpenAccessProject sStubADPFilename
    Else
        oApplication.OpenCurrentDatabase sStubADPFilename
    End If

    oApplication.Visible = false

    WScript.Echo "exporting..."
    Dim myObj

    For Each myObj In oApplication.CurrentProject.AllForms
            If sExpModules = "" or instr(sExpModules, Ucase(myObj.fullname)) > 0 then
                WScript.Echo "  " & myObj.fullname
                oApplication.SaveAsText acForm, myObj.fullname, sExportpath & "\" & myObj.fullname & ".form"
                oApplication.DoCmd.Close acForm, myObj.fullname
            End if
    Next

        'sanitize forms since they contain version stuff that could break on import
        SanitizeTextFiles sExportpath, "form"

    For Each myObj In oApplication.CurrentProject.AllModules
            If sExpModules = "" or instr(sExpModules, Ucase(myObj.fullname)) > 0 then
                WScript.Echo "  " & myObj.fullname
                oApplication.SaveAsText acModule, myObj.fullname, sExportpath & "\" & myObj.fullname & ".base"
            End if
    Next
    For Each myObj In oApplication.CurrentProject.AllMacros
            If sExpModules = "" or instr(sExpModules, Ucase(myObj.fullname)) > 0 then
                WScript.Echo "  " & myObj.fullname
                oApplication.SaveAsText acMacro, myObj.fullname, sExportpath & "\" & myObj.fullname & ".mac"
            End if
    Next
    For Each myObj In oApplication.CurrentProject.AllReports
            If sExpModules = "" or instr(sExpModules, Ucase(myObj.fullname)) > 0 then
                WScript.Echo "  " & myObj.fullname
                oApplication.SaveAsText acReport, myObj.fullname, sExportpath & "\" & myObj.fullname & ".report"
            End if
    Next
    For Each myObj In oApplication.CurrentDb.QueryDefs
            If sExpModules = "" or instr(sExpModules, Ucase(myObj.name)) > 0 then
                Wscript.Echo "Exporting QUERY " & myObj.Name
                oApplication.SaveAsText acQuery, myObj.Name, sExportpath & "\" & myObj.Name & ".query.txt"
            End if
    Next

    WScript.Echo "compacting and overwriting stub ..."
    oApplication.CloseCurrentDatabase
    'oApplication.CompactRepair sStubADPFilename, sStubADPFilename & "_"
    oApplication.Quit

    fso.DeleteFile sStubADPFilename
    WScript.Echo "Deleted StubFile"

    'fso.CopyFile sStubADPFilename & "_", sStubADPFilename
    'fso.DeleteFile sStubADPFilename & "_"


End Function

Sub SanitizeTextFiles(sImportpath, Ext)
    Dim fso, InFile, OutFile, FileName, txt, obj_name, folder
  Dim objectname, objecttype
    Dim oldFileAndPath

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set folder = fso.GetFolder(sImportpath)
    oldFileAndPath = ""

    for each FileName in folder.Files

      if oldFileAndPath > "" then
            fso.Deletefile oldFileAndPath
            fso.MoveFile oldFileAndPath & ".san", oldFileAndPath
            oldFileAndPath = ""
        end if

        objecttype = fso.GetExtensionName(FileName.Name)
        objectname = fso.GetBaseName(FileName.Name)

        if objecttype = "form" then 
          oldFileAndPath = sImportpath & Filename.name
            Set InFile = fso.OpenTextFile(sImportpath & Filename.name, 1, false, -1)
            Set OutFile = fso.CreateTextFile(sImportpath & Filename.name & ".san", True, True)

            Do Until InFile.AtEndOfStream
                txt = InFile.ReadLine
                If Left(txt, 10) = "Checksum =" Then
                    ' Skip lines starting with Checksum
                ElseIf InStr(txt, "NoSaveCTIWhenDisabled =1") Then
                    ' Skip lines containning NoSaveCTIWhenDisabled
                ElseIf InStr(txt, "Begin") > 0 Then
                    If _
                        InStr(txt, "PrtDevNames =") > 0 Or _
                        InStr(txt, "PrtDevNamesW =") > 0 Or _
                        InStr(txt, "PrtDevModeW =") > 0 Or _
                        InStr(txt, "PrtDevMode =") > 0 _
                        Then

                        ' skip this block of code
                        Do Until InFile.AtEndOfStream
                            txt = InFile.ReadLine
                            If InStr(txt, "End") Then Exit Do
                        Loop
                    Else                       ' This line needs to be added
                        OutFile.WriteLine txt
                    End If                     ' This line needs to be added
                Else
                    OutFile.WriteLine txt
                End If
            Loop
            OutFile.Close
            InFile.Close
        else
          oldFileandPath = ""
        end if
    next

    if oldFileAndPath > "" then
            fso.Deletefile oldFileAndPath
            fso.MoveFile oldFileAndPath & ".san", oldFileAndPath
    end if

End Sub

我收到的错误代码是 2128。连同包含以下内容的文本文件:

Database encountered an error while importing the object
'form1'.

Error encountered at line 1. This object was created with a newer version of Database than you are currently running.

The database will ideally need to work with 2010 and 2013.

那你就得在Access 2010这个最早的版本上开发。没有别的方法了。

所以我有一个解决方案。

对于源代码管理,继续使用分解和组合代码。由于开发环境是2016.

要将更新发送到生产环境,请在 access 2010/2013 中执行以下操作:对于部署,将数据库拆分为 frontend/backend 用于 Dev 和 Prod。然后为了将来的更新,将新的前端从 Dev 发送到 Prod。随后,重新链接表。

尝试删除行

Version =19
VersionRequired =19
Checksum =-1389803315

来自LoadFromText之前的文本文件。