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 excel data to access table using ADO

Excel sheet name - Sheet 1 and my data has header,
Access db name - is stored in cell B2
Access table name - Main

Code :
Sub Button14_Click()

' Exports data from the active worksheet to a table in an Access database

Dim cn As ADODB.Connection
Dim r As Long
Dim LastRow As Long
Dim dbfile As String

dbfile = Cells(2, 2).Value

Set cn = New ADODB.Connection

strCon = "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source= " & dbfile

' Late binding, so no reference is needed
Set cn = CreateObject("ADODB.Connection")

cn.Open strCon

' Find LastRow in Col A into the Sheet1
LastRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

' Insert unto a table called Main
scn = "[Excel 8.0;HDR=YES;DATABASE=" & ActiveWorkbook.FullName & "]"
strSQL = "INSERT INTO MAIN " _
& "SELECT * FROM " & scn & ".[Sheet1$A3:AI" & LastRow & "]"

' Execute the statement
cn.Execute strSQL


cn.Close

Set cn = Nothing

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 Data from Excel into existing Table in Access K[_2_] Excel Programming 1 November 30th 09 03:50 PM
excel worksheet export into access table H. Chudhary Excel Worksheet Functions 0 January 23rd 08 03:26 PM
Export Access Table to Excel Don[_27_] Excel Programming 2 September 27th 06 03:39 PM
vb code to export data into existing Access table desperate Excel Programming 2 November 19th 03 06:05 PM
Export Data to Access Table Pete T[_2_] Excel Programming 1 October 10th 03 11:47 PM


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

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"