TTom
Well-known Member
- Joined
- Jan 19, 2005
- Messages
- 518
I'm a newbie to Access.
I want to import data into Excel. My current VBA code below (made from Excel macro recorder) in Excel works fine; however, it imports all fields in my data table.
I want to specify a group consecutive fields. I'm not certain what I need to change. Here is my current code:
<code>
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\DATABASE\employee_db.mdb;Mo" _
, _
"de=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password=""" _
, _
""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactio" _
, _
"ns=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't " _
, _
"Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Employee_Data")
.Name = "employee_db"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\DATABASE\employee_db.mdb"
.Refresh BackgroundQuery:=False
End With
</code>
Any suggestions to specify limited fields to import from table?
Also, I'd like to learn how to send the same data to an Excel array instead of sheet columns. Any good links on this subject?
I want to import data into Excel. My current VBA code below (made from Excel macro recorder) in Excel works fine; however, it imports all fields in my data table.
I want to specify a group consecutive fields. I'm not certain what I need to change. Here is my current code:
<code>
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\DATABASE\employee_db.mdb;Mo" _
, _
"de=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password=""" _
, _
""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactio" _
, _
"ns=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't " _
, _
"Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Employee_Data")
.Name = "employee_db"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\DATABASE\employee_db.mdb"
.Refresh BackgroundQuery:=False
End With
</code>
Any suggestions to specify limited fields to import from table?
Also, I'd like to learn how to send the same data to an Excel array instead of sheet columns. Any good links on this subject?