ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Import Access records into Excel (https://www.excelbanter.com/excel-discussion-misc-queries/170349-import-access-records-into-excel.html)

dksaluki

Import Access records into Excel
 
The code below seems to be the usual code block in order to import
Access records from a particular table into an Excel worksheet, but it
involves a filter, which I do NOT want. I can get it to run just
fine, but I'm having trouble finding how to do it WITHOUT a filter.
Any ideas of how to import everything from Access table to Excel?


With rs
' open the recordset
.Open TableName, cn, adOpenStatic, adLockOptimistic,
adCmdTable
' all records
'.Open "SELECT * FROM " & TableName & _
" WHERE [FieldName] = 'MyCriteria'", cn, , , adCmdText
' filter records

RS2WS rs, TargetRange ' write data from the recordset to the
worksheet

' ' optional approach for Excel 2000 or later (RS2WS is not
necessary)
' For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
' TargetRange.Offset(0, intColIndex).Value =
rs.Fields(intColIndex).Name
' Next
' TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset
data

End With

Tim Zych

Import Access records into Excel
 
"select * from " & tablename

--
Tim Zych
SF, CA

"dksaluki" wrote in message
...
The code below seems to be the usual code block in order to import
Access records from a particular table into an Excel worksheet, but it
involves a filter, which I do NOT want. I can get it to run just
fine, but I'm having trouble finding how to do it WITHOUT a filter.
Any ideas of how to import everything from Access table to Excel?


With rs
' open the recordset
.Open TableName, cn, adOpenStatic, adLockOptimistic,
adCmdTable
' all records
'.Open "SELECT * FROM " & TableName & _
" WHERE [FieldName] = 'MyCriteria'", cn, , , adCmdText
' filter records

RS2WS rs, TargetRange ' write data from the recordset to the
worksheet

' ' optional approach for Excel 2000 or later (RS2WS is not
necessary)
' For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
' TargetRange.Offset(0, intColIndex).Value =
rs.Fields(intColIndex).Name
' Next
' TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset
data

End With





All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com