0

I am using code from here. With some minor modifications. This runs fine in Access 2016 but it is causing an error during import with Access 2013, which will be used in. The database will ideally need to work with 2010 and 2013.

I have created a VM with Access 2013 (32bit). I have run the decompose and compose code with and without the modifications and get the same error. I also changed the file type from mdb to accdb, as that has been suggested to be a cause for failure with Access 2013.

I have tried saving the 2016 version to 2003 mdb. Ran the import/export for that and it didn't work at all. Then opened the mdb in access 2013 and saving it as accdb and that came back with the same 2128 error.

Here is the current version of the export/decompose code. The aim was to remove lines that are not compatible from 2016 to 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

The error code I am getting is 2128. Along with a text file containing:

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.

Aaron C
  • 301
  • 1
  • 8

3 Answers3

2

Try to delete lines

Version =19
VersionRequired =19
Checksum =-1389803315

From text file before LoadFromText.

4dmonster
  • 3,012
  • 1
  • 14
  • 24
1

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

Then you will have to develop in Access 2010, the earliest version. There is no other method.

Gustav
  • 53,498
  • 7
  • 29
  • 55
0

So I have a solution.

For source control, continue using the decompose and compose code. Since the development environment is 2016.

To send updates to the production environment, in access 2010/2013, do the following: For deployment split the database into frontend/backend for both the Dev and Prod. Then for future updates send the new frontend from Dev to Prod. Followed by, relinking the tables.

Aaron C
  • 301
  • 1
  • 8