iwanalearn
Technical User
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
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