LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default String Building for Where Clause in Query

Hi,

I'm hoping someone can help with a very simple problem. I have a
column in excel that contains numbers of 9 digits each. I have an
access table containing these numbers and a lot of additional
information. I am trying to execute a query through code, that will
return this additional data. I have made the query work by going down
each line in excel and opening a new query and pulling back the
information WHERE the article number = a variable containing the
number from excel. This works fine but is slow. What I would like to
do is build a string containing all the article numbers, to act as a
multiple criteria WHERE query. I have had this work when I have used
the numbers directly, but when I try it through code, I get a "Type
mismatch" error as soon as the macro reaches the query. Below is the
string building and query code. Can anyone point out why this is not
working?


saparticle = ActiveCell
criteriastring = "(`Final Output`.Article='" & saparticle & "') "
While ActiveCell.Offset(1, 0) < ""
ActiveCell.Offset(1, 0).Select
saparticle = ActiveCell
criteriastring = criteriastring & "OR (`Final Output`.Article='" &
saparticle & "') "
Wend
Range("R4").Name = "onedctarget"


With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;DBQ=H:\*******.mdb;DefaultDir=H:
\*****;DriverId=281;FIL=MS Access;MaxBuffe" _
), Array("rSize=2048;PageTimeout=5;")),
Destination:=Range("onedctarget"))
.CommandText = Array( _
"SELECT `Final Output`.Article,`Final Output`.Site,`Final
Output`.Listed, `Final Output`.OneDC" & Chr(13) & "" & Chr(10) &
"FROM
`H:\****`.`Final Output` `Final Output`" & Chr(13)
& "" & Chr(10) & "WHERE " & criteriastring)
.Name = "Query from MS Access Database"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh BackgroundQuery:=False
End With


Any help would be much appreciated.


Thanks,


Dan

 
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
$ sign in SQL clause in MS Query FredAker Excel Discussion (Misc queries) 1 July 30th 08 10:43 AM
String Building for Where Clause in query [email protected] Excel Programming 2 June 25th 07 10:54 PM
conversion to formula of string contaning IF clause JeanBQ Excel Programming 1 March 31st 06 05:49 PM
Crazy problem when using a WHERE-clause in a SQL query kuhni Excel Programming 1 July 28th 04 12:42 PM
Query Sheet using a WHERE clause? Icemak[_3_] Excel Programming 1 January 7th 04 11:47 PM


All times are GMT +1. The time now is 11:24 AM.

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

About Us

"It's about Microsoft Excel"