Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2012, 05:47 PM
Authorized User
 
Join Date: Aug 2004
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Arsi
Default Run Time Error Too Few Parameters. Expected 2.

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()





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Too few parameters. 1 expected !!! chacquard Access VBA 2 June 21st, 2005 08:00 AM
Error:0x80040E10 -Too few parameters. expected 1 mikest Access ASP 2 December 5th, 2004 10:31 PM
run time error: Object expected shoakat Classic ASP Databases 5 September 22nd, 2004 03:17 PM
Error "Too Few Parameters - Expected 1" timmaher Access VBA 2 August 31st, 2004 04:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.