Требуется ошибка объекта при импорте текстового файла - PullRequest
0 голосов
/ 07 ноября 2019

Я пытаюсь запустить импорт, и в конце я постоянно получаю указанную ошибку, я считаю, что мои запросы верны, я просто не могу найти, где я ошибся с моим кодом. Пожалуйста помоги!

Я пытался изменить последний запрос, удалить его вообще, ошибка остается.

Он приходит сразу после DoCmd.OpenQuery ("q_Reported Amount Population")

Option Compare Database
Global gstrSelectedFile As String

Public Sub ImportAirfareFile()
On Error GoTo ImportAirfareFileError
    Dim objFS As Object, objFolder As Object
    Dim objFiles As Object, objF1 As Object
    Dim strFolderPath As String
    Dim rstFilesImported As Recordset
    Dim db As DAO.Database
    Dim UserName As String

    Dim StartTime As Double
    Dim TimeElapsed As Double

    'Path where we are taking the files FROM
    strFolderPath = "\\mmpfs04\Shared\ASSC\Airfare\CWT Source Files\"

    'Use FileSystem object methods to access the data
    'Set objFS = CreateObject("Scripting.FileSystemObject")
    'Set objFolder = objFS.GetFolder(strFolderPath)
    'Set objFiles = objFolder.Files

    Set db = CurrentDb
    Set rstFilesImported = db.OpenRecordset("tblFlightFilesImported")

    'Choose file to import
    Call UseFilePicker(strFolderPath)

    'gstrSelectedFile has name of File that was selected from FilePicker
    ' If no file selected, exit
    If gstrSelectedFile = "" Then
        Exit Sub
    End If


    'If the file is already listed as imported, don't import. Otherwise, continue importing.
    If DCount("[FileName]", "tblFlightFilesImported", "[FileName] = """ & gstrSelectedFile & """") = 0 Then

        'If not CSV file, exit with error.  Otherwise import
        If Right(gstrSelectedFile, 3) = "csv" Then

            DoCmd.Hourglass True

            'Import records into Monthly Flights table
            DoCmd.TransferText acImportDelim, "CWTMonthlyFlightSpecs", "tbl_MonthlyFlightsTemp", gstrSelectedFile

            DoCmd.OpenQuery ("qry_AddMonthlyFlights")

            'Update tblFilesImported with File Name, Username and Date Imported
            With rstFilesImported
                .AddNew
                    !FileName = gstrSelectedFile
                    !UserName = UserName
                    !DateImported = Date
                .Update
                .Close
            End With
            MsgBox "Flights were imported."

                'Runs Query to add the name of the file imported to the records imported
            CurrentDb.Execute ("AddFileNameToRecord")
                'Runs Query to append all US HCP flights to New Monthly Flights Table
            CurrentDb.Execute ("q_Append to New Monthly Flights")
                'Runs Query to move HCP records to HCP specific table, which feeds form
            CurrentDb.Execute ("q_Append HCP Records")
               'Runs Query to remove blank spaces in the product code field to
            CurrentDb.Execute ("q_Delete New Monthly Flights Temp tbl")
                'Runs Query to remove blank spaces in the product code field to
            CurrentDb.Execute ("q_Product Code - Space Removal")
                'Runs Query to seperate products from Client Defined 13 into the product fields 1-5
            CurrentDb.Execute ("q_Product 1-5")
                'Runs Query to remove the "US-" in front of the State for both Origin and Destination States
            CurrentDb.Execute ("q_State Format")
                'Runs Query to populate Destination Country Code
            CurrentDb.Execute ("q_Destination Country Code Update")
                'Runs Query to populate the Reported Amount field with the amount from Paid Fare
            DoCmd.OpenQuery ("q_Reported Amount Population")

        Else
            MsgBox "You must import a csv file. Please check file and try again."
                GoTo ImportAirfareFileExit
        End If

        Call ExportToXlsx

            DoCmd.Hourglass False

            MsgBox "File Load Process Completed"

    Else
        MsgBox "It looks like you already imported this file.  Please check and try again."
        GoTo ImportAirfareFileExit


    End If

ImportAirfareFileExit:
    If Not db Is Nothing Then
        Set db = Nothing
    End If
    If Not objFS Is Nothing Then
        Set objFS = Nothing
    End If
    If Not rstFilesImported Is Nothing Then
        Set rstFilesImported = Nothing
    End If
    Exit Sub

ImportAirfareFileError:
    MsgBox "There has been an error: " & Err.Number & " Error Description: " & Err.Description
    GoTo ImportAirfareFileExit

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...