Skip to content
Advertisement

VBA error while querying a Tab limited Text file with headers – “no value given for one or more required parameters”

My Text file is Tab delimited and does have the header Field "Datum". I intend to read the data between two given timestamps (along rows) into an Excel File and figured using the ADO and SQL approach would be the best way to go about it, since this would avoid use of arrays and looping.

My Text file looks like:

enter image description here

    Sub FetchZaehlerData()

        Dim wb As Workbook
        Set wb = ThisWorkbook
        Dim myConn As New ADODB.Connection
        Dim myRecordSet As New ADODB.Recordset
        Dim mySQLQry As String
        
        Dim myFSO As Object
        Set myFSO = CreateObject("Scripting.FileSystemObject")
        Dim myFilePath As String
        
        myFilePath = "P:PROJECTFILESO&MMetering Data20201_2020LS20200201"
        
        myConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=" & myFilePath & ";" & _
                "Extended Properties='text;HDR=YES';"
                
        
        
        mySQLQry = "SELECT [Datum] FROM [TenneT2_P802_20200201064325.txt]"
        
        Debug.Print mySQLQry
        
        myRecordSet.Open mySQLQry, myConn
        
        wb.Worksheets("Sheet2").Range("F3").CopyFromRecordset myRecordSet
        
        myRecordSet.Close
        myConn.Close
    
    Exit Sub  

Advertisement

Answer

  1. You need to specify FMT=TabDelimited in the Extended Properties part of the ConnectionString

  2. You need to provide a schema.ini file, as answered here

It’s unfortunate that the error message doesn’t relate in any way to the problem you are having, but if you fix the two points I make, “it should all just work”.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement