当我从Access中的表中获取数据时,选择特定的行

时间:2014-08-11 18:00:55

标签: excel

这是我的代码。值得关注的是.Commandtext行。

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
    "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=C:\Users\Matthew.McLeod\Desktop\HOBP_14.accdb;Mode=Share" _
    , _
    " Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OL" _
    , _
    "EDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet" _
    , _
    " OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Loc" _
    , _
    "ale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False" _
    ), Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdTable
    .CommandText = "Select January,February,March,April,May,June,July,August,September,October,November,December,[Year 1],[Year 2],[Year 3] from Sum_FTE_SG"
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .SourceDataFile = "C:\Users\Matthew.McLeod\Desktop\HOBP_14.accdb"
    .ListObject.DisplayName = "Table_HOBP_14.accdb"
    .Refresh BackgroundQuery:=False
End With

ActiveSheet.ListObjects("Table_HOBP_14.accdb").ShowTableStyleRowStripes = False
ActiveSheet.ListObjects("Table_HOBP_14.accdb").ShowHeaders = False

基本上我需要获取其中column =“Facility”=“One”的特定行,我该怎么做?现在我抓住了特定的列,但不管设施如何,都抓住了所有行。

1 个答案:

答案 0 :(得分:0)

想出来:

.CommandText = "Select January,February,March,April,May,June,July,August,September,October,November,December,[Year 1],[Year 2],[Year 3] from Sum_FTE_SG Where Facility = 'One'"