Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 May 16th, 2007, 10:14 AM
Registered User
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel vba query not working, pls help me.


When i try to use the query "SELECT name, num FROM [Sheet2$] WHERE ((name IN ('A', 'C')) AND (num IN ('2')))" in excel 2000 vba i'm getting the Runtime error -'-2147217913 (80040e07) Pls help me.

The table is

name num code1 code2
A 1 aa 5
B 1 bb 6
A 2 aa 5
C 1 cc 7
D 3 dd 7
A 1 aa 6
B 2 bb 5
B 2 bb 5

The code is
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=D:\Kavitha\CM\NPI\Scorecard\TESTFILTER.xls; " & _
"Extended Properties=Excel 8.0;"

End With

strQuery = "SELECT name, num FROM [Sheet2$] WHERE name IN ('A', 'C') AND num IN ('2')"
rs.Open strQuery, cn, 2

The above query is working well in sql query analyser , but not in excel vba. pls help me to solve this issue.

Thanks a lot

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel formula not working in vba yogeshyl Excel VBA 2 December 12th, 2007 02:27 AM
Excel formula not working in VBA yogeshyl Excel VBA 2 July 19th, 2007 03:57 AM
SQL Date query in Excel VBA lanewalk Excel VBA 2 September 27th, 2006 02:04 AM
VBA help pls lplBoonah Access VBA 1 August 14th, 2006 12:46 PM
Using Mapi to send emails in VBA - Help pls Magic_Hat Access VBA 0 April 21st, 2004 07:29 AM

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