There is a table in Access with all of our historical data. The table is organized with different Pricing Hubs. I'd like to pull into Excel only the data from one specific Hub at at time. I'd like this to happen by inputting which Hub I want in a cell in Excel, clicking a button to refresh the data and it pulls it from our Access Database instead of relinking each time with a new parameter.
I've recorded macro as I do this and this is what I have.
The PullHub string will change based on what I type into cell N1. I'd like Access to pull only that, but I cannot get it to recognize PullHub as a string instead of just text with the colons around it. Anything else I try either errors or gives me a blank value.
Thank you very much.
I've recorded macro as I do this and this is what I have.
Sub Macro1()
'
' Macro1 Macro
'
Dim PullHub As Variant
PullHub = Range("N1").Value
MsgBox PullHub
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Documents and Settings\#######\Desktop\#######.accdb;DefaultDir=C:\Docume" _
), Array( _
"nts and Settings\jabbar_ahmad\Desktop;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("$A$1")).QueryTable
.CommandText = Array( _
"SELECT `Historical Prices`.SETTLEMENT_PRICE_DATE, `Historical Prices`.SETTLEMENT_PRICE, `Historical Prices`.STRIP, `Historical Prices`.`PROD DESC`, `Historical Prices`.IDENTIFIER, `Historical Prices`." _
, _
"HUB, `Historical Prices`.TRANSACTION" & Chr(13) & "" & Chr(10) & "FROM `Historical Prices` `Historical Prices`" & Chr(13) & "" & Chr(10) & "WHERE (`Historical Prices`.HUB='PullHub')" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_MS_Access_Database"
.Refresh BackgroundQuery:=False
End With
End Sub
The PullHub string will change based on what I type into cell N1. I'd like Access to pull only that, but I cannot get it to recognize PullHub as a string instead of just text with the colons around it. Anything else I try either errors or gives me a blank value.
Thank you very much.