Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference worksheet cell in script 1

Status
Not open for further replies.

iwanalearn

Technical User
Sep 21, 2001
22
US
I use a ODBC query to populate a worksheet. I need to do the query by date, so I need to change the date in the VB script each time. Is there a way that I can enter a date in a worksheet cell and have the script reference that cell for the date.
Below is the code I use now, the red text is the date I want to reference.

With Selection.QueryTable
.Connection = _
"ODBC;DSN=???;ServerName=???;ServerDSN=SimbaSrv;UID=???;PWD=???;ArrayFetchOn=1;ArrayBufferSize=8;"
.CommandText = Array("SELECT Product.Code, Product.Type, Product.Date, Data.Numeric, Product.Cost, Product.Quantity" & Chr(13) & "" & Chr(10) & "FROM Data Product, Product" & Chr(13) & "" & Chr(10) & "WHERE Product.Code = Product.Code AND
((Product.Type=1) AND (Product.Date Between '20010301' And '20010331') OR
(Product.Type=5) AND (Product.Date Between '20010301'And '20010331') OR
(Product.Type=6) AND (Product.Date Between '20010301' And '20010331'))")

.Refresh BackgroundQuery:=False
End With

Thanks for your help
 
I don't know much about Excel but something like:

"Product.Type=1) AND (Product.Date Between '" & sheets("sheetName").cells(Row,Col) & "'

Nick
 
WOW!!! nickjar2,
It works great. I can enter the dates in a cell on a worksheet and my query does it's job. I've been trying to make this work for some time, with now success.
Again Thanks
 
WOW!!! I can't believe it works either.My excel knowledge isn't too hot!

Good luck,

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top