Public Function ImportText(strFullPathFile As String, strTblName As String) 'Purpose : Import delimited file. 'DateTime : 8/20/2018 08:34 'Author : Bill Mosca 'Requires : MS Scripting Runtime Dim fso As FileSystemObject Dim ts As TextStream Dim strMSG As String Dim strline As String Dim varLine As Variant Dim ChkHdr As Boolean 'Table stuff Dim db As DAO.Database Dim tdf As TableDef Dim fld As Field Dim x As Integer Dim y As Integer Dim aryColumns As Variant Dim bolFirstSkipped As Boolean On Error GoTo err_PROC Set db = CurrentDb Set tdf = db.TableDefs(strTblName) 'Array is zero-based and we 'won't be using primary key (AutoNumber) x = tdf.Fields.Count - 2 ReDim aryColumns(x) For Each fld In tdf.Fields 'Skip primary key (first field in table) If bolFirstSkipped = False Then GoTo LoopMe aryColumns(y) = fld.Name y = y + 1 LoopMe: bolFirstSkipped = True Next Set fso = CreateObject("Scripting.FileSystemObject") 'Open file to verify. Set ts = fso.OpenTextFile(strFullPathFile, ForReading) 'Read first line in File. Should be headers. strline = ts.ReadLine 'remove quotes if any. strline = Replace(strline, Chr(34), "") 'dump line into an array. varLine = Split(strline, ",") 'Check FY and FP. x = UBound(aryColumns) For y = 0 To x If varLine(y) = aryColumns(y) Then 'Header OK. ChkHdr = True End If Next If ChkHdr = False Then strMSG = "Headers don't match table fields" GoTo exit_PROC End If 'Close text file Set ts = Nothing Set fso = Nothing 'Import using saved import spec DoCmd.TransferText TransferType:=acImportDelim, SpecificationName:="mySpecName", _ TableName:="myTablename", FileName:=strFullPathFile, hasfieldnames:=True exit_PROC: On Error Resume Next SysCmd acSysCmdClearStatus Set ts = Nothing Set fso = Nothing Set tdf = db.TableDefs(strTblName) Set db = CurrentDb Exit Function err_PROC: Dim strErrMsg As String Dim lngIcon As Long strErrMsg = "Error " & Err.Number & " (" & Err.Description & ") " _ & "occurred in procedure ImportText of " _ & "VBA Document Module1" lngIcon = vbOKOnly + vbInformation MsgBox strErrMsg, lngIcon, "Error" Resume exit_PROC End Function