Hello,

I'm having an issue with my code below. I'm using the CurDir function to find the current directory (which also holds the data csv file). The directory is found as well as the file, but when trying to query the data source I get the error too few parameters expected 2. When I place the data source file into my local C:\ drive and run the application file from the existing location which is a mapped network drive, everything runs as it should. Only when I place the data source into the network drive, I get that error. Any ideas what may be causing this?

Thanks in advance.

Private Sub UserForm_Initialize()
'Set CSV file name
theFileName = "DataFile.csv"

'Set current directory path
thePath = CurDir("Z:\")

'Dim objConn As ADODB.Connection
Set objConn = New ADODB.Connection

'Create connection string and open the connection
objConn.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & thePath & ";Extensions=asc,csv,tab,txt;Persist Security Info=False;"
objConn.CursorLocation = adUseClient
objConn.Open

'Create a command object to use in the queries
Set objCmd = New ADODB.Command
objCmd.ActiveConnection = objConn

'Query to select the distinct list of companies in the CSV file for user to select
sDDLSQL = "SELECT DISTINCT [Company], [Company Name] FROM " & theFileName & " ORDER BY [Company]"
'Execute Query
objCmd.CommandText = sDDLSQL
Set rsDDLData = objCmd.Execute()

'Move to the first record in the recordset
rsDDLData.MoveFirst

Dim x As Integer
x = 0
'Clear the list in the combobox and put in new set of companies pulled by query
With Me.cboCode
    .ColumnCount = 2
    .ColumnWidths = Len(rsDDLData.Fields(1)) + 20
    .Clear
    Do
        .AddItem
        .List(x, 0) = rsDDLData.Fields(0) 'rsDDLData![Company]
        .List(x, 1) = rsDDLData.Fields(1) 'rsDDLData![Company Name]
        x = x + 1
        '.AddItem rsDDLData![Company] 'rsDDLData.Fields(0)
        rsDDLData.MoveNext
    Loop Until rsDDLData.EOF
End With

End Sub