Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Export specific fields from access to Excel


Cells(1, 8) contains full path&name of access db ex: C:\dbfolder\test.accdb
Main is the table in access.


'This macro requires ADO X.X Object Library reference
Sub GetDBData()
Dim cn As Object, rs As Object
Dim intColIndex As Integer
Dim DBFullName As String
Dim TargetRange As Range

DBFullName = Cells(1, 8)

On Error GoTo errfetch

Application.ScreenUpdating = False
Range("A4:V20000").ClearContents
Set TargetRange = ActiveSheet.Range("A4")

Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=" & DBFullName & ";"

Set rs = CreateObject("ADODB.Recordset")
rs.Open "SELECT [header1],[header2],[header3],[header4] FROM Main ", cn, , , adCmdText

' Write the field names
'For intColIndex = 0 To rs.Fields.Count - 1
'TargetRange.Offset(1, intColIndex).Value = rs.Fields(intColIndex).Name
'Next

' Write recordset
TargetRange.CopyFromRecordset rs

LetsContinue:
Application.ScreenUpdating = True
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
On Error GoTo 0
Exit Sub
errfetch:
MsgBox "Error Description :" & Err.Description & vbCrLf & _
"Error at line :" & Erl & vbCrLf & _
"Error Number :" & Err.Number
Resume LetsContinue
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
export re-order input fields to export file [csv] madisonpete Excel Worksheet Functions 0 November 30th 07 03:51 PM
Macro to Export Selected fields to an Existing Access Database ernie Excel Programming 1 March 13th 06 05:01 PM
export access to excel. change access & update excel at same time fastcar Excel Discussion (Misc queries) 0 June 24th 05 09:27 PM
Access -> Excel: How to export fields > 255 characters Gabriel Martin Excel Discussion (Misc queries) 1 March 9th 05 01:37 PM
Export Access Record to Specific Cells in Excel Elecdave Excel Discussion (Misc queries) 0 December 29th 04 04:49 PM


All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"