Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL queries with Excel in VBA to populate a spreadsheet

Hi,

Can somebody help me on the following point?

I want to use ODBC connection to another Excel file and
set up an SQL request with a QueryTable object.
The result to filter depends on IDs given by the user
in one cell of the workbook. So far so good.

My problem is that I do not know how to format the SQL
request nor write the corresponding VBA code to SQL
request several ID at the same time (outcomes as an union
of up to three IDs).
What to change to the following code?

rq = "Select * from `Table$` Where (CRD_ID=?)"
Me.QueryTables(1).Parameters.Add( "CRD_ID", xl...)
Me.QueryTables(1).Parameters(1).SetParam xlRange, Range
("A1")

Thanks a lot.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default SQL queries with Excel in VBA to populate a spreadsheet

Just build th esql query
Sql = "Select [field1],[Field2] from mydata where" & _
"[field1]='" & test1 & "', and [Field2]=" & test2
& ";"

note that test1 is textual - hence the single quote
bracing it and i've let test2 be numeric

see
http://www.xl-
expert.com/html_pages/dataConnectivity_Excel.html

Patrick Molloy
Microsoft Execl MVP

-----Original Message-----
Hi,

Can somebody help me on the following point?

I want to use ODBC connection to another Excel file

and
set up an SQL request with a QueryTable object.
The result to filter depends on IDs given by the user
in one cell of the workbook. So far so good.

My problem is that I do not know how to format the SQL
request nor write the corresponding VBA code to SQL
request several ID at the same time (outcomes as an

union
of up to three IDs).
What to change to the following code?

rq = "Select * from `Table$` Where (CRD_ID=?)"
Me.QueryTables(1).Parameters.Add( "CRD_ID", xl...)
Me.QueryTables(1).Parameters(1).SetParam xlRange, Range
("A1")

Thanks a lot.

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a spreadsheet from a data set rev Excel Worksheet Functions 1 September 26th 08 05:13 PM
Access macros in Excel - populate results in spreadsheet Dawn Excel Discussion (Misc queries) 3 August 28th 07 12:30 AM
I cannot refresh all of the queries in my spreadsheet Peter Excel Discussion (Misc queries) 0 July 25th 06 04:23 PM
Finding and killing all Access queries in an Excel spreadsheet travis Links and Linking in Excel 1 December 13th 05 03:01 AM
Can I use a spreadsheet to populate an offline calender in excel? jimmykins Excel Discussion (Misc queries) 0 March 16th 05 10:45 PM


All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"