我正在使用here中的代码。经过一些小的修改。这在Access 2016中运行良好,但是在使用Access 2013导入时会导致错误,将在其中使用该数据库。理想情况下,数据库需要与2010和2013配合使用。
我用Access 2013(32位)创建了一个VM。我已经运行了分解和编写代码,并进行了修改,没有修改,并且得到了相同的错误。我也将文件类型从mdb更改为accdb,因为这被认为是Access 2013失败的原因。
我尝试将2016版本保存到2003 mdb。为此执行了导入/导出操作,但它根本不起作用。然后在Access 2013中打开mdb,并将其另存为accdb,然后返回相同的2128错误。
这是导出/分解代码的当前版本。目的是删除从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。以及一个包含以下内容的文本文件:
数据库在导入对象时遇到错误
“ form1”。在第1行遇到错误。 该对象是使用较新版本的数据库创建的 比您当前正在运行。
答案 0 :(得分:1)
理想情况下,该数据库需要与2010和2013协同工作。
然后,您将必须在最早的版本Access 2010中进行开发。没有其他方法。
答案 1 :(得分:1)
尝试删除行
Version =19
VersionRequired =19
Checksum =-1389803315
来自LoadFromText
之前的文本文件。
答案 2 :(得分:0)
所以我有一个解决方案。
对于源代码控制,请继续使用分解和编写代码。由于开发环境是2016年。
要将更新发送到生产环境,请在Access 2010/2013中执行以下操作:对于部署,将数据库分为Dev和Prod的前端/后端。然后,为了将来进行更新,将新的前端从Dev发送到Prod。接下来,重新链接表。