0

So I've been at days now trying to solve this bug. After having all functions for Access objects exported, removing binary data from specified fields, and importing Access objects to fresh database, this is the error I'm still having issues with.

Run-time error '-2147417851 (80010105)':

Method 'LoadFromText' of object '_Application' failed.

Edit:
As requested, here is the full function code that handles the import. The error is caused in the "Form" LoadFromText line:

Private Sub Setup_New_Database_File(ByVal srcFileName As String, ByVal destPath As String, ByVal txtDumpPath As String)

' srcFileName: Name of the old datbase file
' destPath: Destination path of where new Access object is created at
' txtDumpPath: Directory housing all exported Access text files
Dim accApp As Access.Application
Set accApp = New Access.Application

' Creating a new Access object
iDate = " (" & Format(Date, "mm-dd-yy") & ")"
newDBName = destPath & srcFileName & iDate & ".accdb"

' Auto-delete existing file with same name
If Dir(newDBName) <> "" Then
    SetAttr newDBName, vbNormal
    Kill newDBName
End If

With accApp

    .DBEngine.CreateDatabase newDBName, DB_LANG_GENERAL, dbVersion120
    .OpenCurrentDatabase (newDBName)
    .Visible = False
    .Echo False             ' Hide any other Access windows apart from current
    .UserControl = False

    ' --------------------------------------------------------------------------------------------
    'On Error GoTo Err_SetupNewDatabaseFile

    ' Iterate through the directory containing textfile versions of Access objects created previously from SaveAsText,
    ' and write back to new Access DB file instance
    Dim dirObject As Variant
    fp = txtDumpPath & "\" & "*.txt"
    dirObject = Dir(fp)

    Do While Len(dirObject) > 0

        cFilePath = txtDumpPath & "\" & dirObject

        ' Extract the text file type: [Form_, Module_, Query_, Report_, Script_, Table_]
        ' Every naming convention only has one "_" character.
        fTarget = InStr(dirObject, "_")
        fStart = fTarget + 1
        cfLength = Len(dirObject)

        cFileName = Mid(dirObject, fStart, cfLength)      ' E.G: objectname.txt

        pTarget = InStrRev(cFileName, ".")
        pEnd = pTarget - 1

        If dirObject = "Database Linked Tables.txt" Then

            ' Our Linked Tables are large in data, so opted to add them in via connection.
            Dim fso As Object, oFile As Object, cLine As String
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set oFile = fso.OpenTextFile(cFilePath, ForReading, False)

            Do Until oFile.AtEndOfStream

                cLine = oFile.ReadLine

                If cLine = "" Or cLine = Null Then
                    GoTo Next_Iteration   'Moving on...
                Else

                   ' Need to check for Driver sources
                   If cLine = "xResults Local" And Special_Character_Match(cLine, "xResults") = True Then
                       tPath = DLookup("[Database Path]", "[Tables List]", "[Table Name] = 'xResults'")
                       accApp.DoCmd.TransferDatabase acLink, "Microsoft Access", tPath, acTable, cLine, cLine, False
                   ElseIf cLine <> "" Or cLine <> Null Then

                       ' Local vs ODBC:::
                       option1_path = DLookup("[Database Path]", "[Tables List]", "[Table Name] = '" & cLine & "'")
                       option2_path = DLookup("[Connect]", "[Tables List]", "[Table Name] = '" & cLine & "'")

                        If option1_path <> "" Or option1_path <> Null Then
                            accApp.DoCmd.TransferDatabase acLink, "Microsoft Access", option1_path, acTable, cLine, cLine, False
                        ElseIf option2_path <> "" Or option2_path <> Null Then

                            option2_source = DLookup("[MySQL Name]", "[Tables List]", "[Table Name] = '" & cLine & "'")
                            option2_setTableNameTo = cLine
                            connectString = "ODBC;" & option2_path & ";"

                            accApp.DoCmd.TransferDatabase acLink, "ODBC Database", connectString, acTable, option2_source, option2_setTableNameTo
                        End If
                   End If

                End If   'End of cLine = "" check
 Next_Iteration:
            Loop

            oFile.Close
            Set fso = Nothing
            Set oFile = Nothing
            '-----------------------------------------------------------------------------------------------------------------
        Else

            ' Add all textfiles in txtdump dir to new Access file
            accObjectType = Left(dirObject, fTarget - 1)  ' E.G: Form
            accObjectName = Left(cFileName, pEnd)         ' E.G: objectname

            ' Reconvert accObjectName to its original state

            Select Case accObjectType
                Case "Form"
                    MsgBox "File Name: [" & accObjectName & "], Form Name: [" & cFilePath & "]"
                    'On Error Resume Next
                    accApp.LoadFromText acForm, accObjectName, cFilePath
                Case "Module"
                    accApp.LoadFromText acModule, accObjectName, cFilePath
                Case "Query"
                    accApp.LoadFromText acQuery, accObjectName, cFilePath
                Case "Report"
                    accApp.LoadFromText acReport, accObjectName, cFilePath
                Case "Script"
                    accApp.LoadFromText acMacro, accObjectName, cFilePath
                Case "Table"
                    accApp.DoCmd.TransferText acImportDelim, , accObjectName, cFilePath, True
            End Select
        End If

        ' Next file iteration
NextFileIteration:
        dirObject = Dir
    Loop
End With

' ---------------------------------------------------------------------------------------------
' Variable Cleanup
accApp.Echo True
accApp.Quit
Set accApp = Nothing

End Sub

And where an example Form text file (with the necessary data removed) is here

Where to differentiate the objects, files in cFilePath follow "\dir...\Form_FormName.txt" format, while accObjectName is just "FormName". The issue I'm having is importing Access forms.

Things I have tried:
- I have removed the "NoSaveCTIWhenDisabled =1" lines from the form files, since in old mdb formats this was causing import issues. (Even with this line on still caused import issues)
- I have also tried removing all blank lines from the text files, in case the command had issues with reading them.

While a small subset of form objects to get imported, not all of them do, resulting in this error. Checking the files themselves to see why, I can't make sense of them since the format looks relatively the same for all of them. What would be a reason for this automation error to occur? All other export/parsing functions seem to run fine...

Wyntile
  • 5
  • 4
  • This could be because of a number of reasons. E.g. you could be importing forms with objects that require a reference without having set up the reference first, or there could be a version mismatch (see [this question](https://stackoverflow.com/q/54328256/7296893)). To narrow it down, please try to provide a [mcve]. If you can reproduce this on a relatively simple form, you could include the contents of the text file. – Erik A Mar 20 '19 at 15:30
  • @ErikA Oh okay. I have provided both the full function and example text file. – Wyntile Mar 20 '19 at 17:36
  • Try to delete the entire blocks, not just their content. So including the begin and end stuff – Erik A Mar 20 '19 at 18:10
  • @ErikA ....Huh. So it ended up being a parser function problem instead. I had to create another version of it since the previous version had errors, and since the new one had no problems I assumed it was the above function. But thank you, with those removed there were no problems! – Wyntile Mar 20 '19 at 18:36

0 Answers0