View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 1,560
Default Data Import Cell Reference

This is part of your code:
"WHERE (tblStoreTotals.SalesDate={ts '2004-05-31 00:00:00'})" & Chr(13) &

Create a variable to accept the date your need, say ToDate,then rplae with
this:
"WHERE (tblStoreTotals.SalesDate={ts '"&(ToDate)&"'})" & Chr(13) &

Hope this works for you.

"John" wrote:

I wish to include cell reference as parameters to a Data Import module that
I have recorded but not sure of the syntax. What I have recorded works great
but when I want to modify the dates I have to change the hard code. My dates
within the macro are currently between 31/05/2004 and todays date. Say if a
cell reference exists for 31/5/2004 in Sheet(Sales) Range C5 - how could I
incorporate that below so that my Data Import could update to whatever date
is in Sale C5

Thanks



Sub PullSales()

Sheets("Database2").Select
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DBQ=E:\JIM1_be.mdb;DefaultDir=E:\;Driver={Mi crosoft Access
Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxSca" _
), Array( _

"nRows=8;PageTimeout=5;SafeTransactions=0;Threads= 3;UID=admin;UserCommitSync
=Yes;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT tblStoreTotals.StoreNo, tblStoreTotals.SalesDate,
tblStoreTotals.TaxableSales" & Chr(13) & "" & Chr(10) & "FROM
`E:\OKR1_be`.tblStoreTotals tblStoreTotals" & Chr(13) & "" & Chr(10) &
"WHERE (tblStoreTotals.SalesDate={ts '2004-05-31 00:00:00'})" & Chr(13) &
"" & Chr(10) & "ORD" _
, "ER BY tblStoreTotals.StoreNo, tblStoreTotals.SalesDate")
.Name = "Query from Pull Sales"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub