View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gustavo[_4_] Gustavo[_4_] is offline
external usenet poster
 
Posts: 6
Default VB Code for MS Query

Hi Everyone,
I have a piece of code in Excel 2000 to retrieve some
data from Access 2000 using MS Query and it works fine.
The problem is that I need to copy down the formulas to
the right of the data and it does not do it even tough I
have the line: FillAdjacentFormulas=True on it.
The funny thing is that if I do a straight "refresh" in
the worksheet it copies all the formulas perfectly. The
reason why I need to do it using a macro is because I
need the user to select some criteria from another
worksheet. (I tested this and it works too)

Here's the code:

With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y(
_
"ODBC;DSN=MS Access Database;DBQ=S:\FF
Files\Profit Model.mdb;DefaultDir=S:\FF
Files;DriverId=25;FIL=MS Access;MaxBufferSize=" _
), Array("2048;PageTimeout=5;")),
Destination:=Range("A10"))
.CommandText = Array( _
----SQL Statement Here----
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = True
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

Is there anything that I am missing or doing wrong?
I thank you all in advance
Gustavo