Hello,
The VBA code in the Excel sheet and the .csv file I have runs fine when placed in the c:\ drive of the user's machine, but when both the .csv file it uses and the excel file are on a network drive I get the error message run time error too few parameters. Expected 2.
And I only get the above error message when I use a specific query below. If I change the query to select * for example it runs fine. It doesn't make sense to me can you please help?
Thank you!
Code:
sFileName = "Labor.csv"
'Set current directory path
sPath = CurDir("S:\")
'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=" & sPath & ";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 " & sFileName & " ORDER BY [Company Name]"
'Execute Query
'objCmd.CommandTimeout = 3600
'objCmd.CommandType = adCmdText
objCmd.CommandText = sDDLSQL
'Set rsDDLData = New ADODB.Recordset
Set rsDDLData = objCmd.Execute()