View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John[_78_] John[_78_] is offline
external usenet poster
 
Posts: 87
Default Data Import Cell Reference

David thanks for your reply, did what you said and replaced with the code
below, now it stopping at the line

..Refresh BackgroundQuery:=False

and returns a SQL syntax error Run Time 1004

I have deleted all old Query Tables, but it just won't run. I've tried
changing FALSE to TRUE above but still the same




Sub PullSales()

Dim FromDate As Variant
FromDate = Workbooks("Pull Gross Sales for 2005 Financial
Year.xls").Worksheets("Sheet2").Range("A1").Value

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:\JIM1_be`.tblStoreTotals tblStoreTotals" & Chr(13) & "" & Chr(10) &
"WHERE (tblStoreTotals.SalesDate={ts '" & (FromDate) & "'})" & 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