Excel Export to Access via VBA

  • Thread starter AccessUser777 via OfficeKB.com
  • Start date
A

AccessUser777 via OfficeKB.com

Hi all.
Hopefully someone can point me in the right direction. Here's what I want to
do.
I want to be able to click on a command button and export whatever logs that
have been entered into the spreadsheet to be exported into an Access db with
the same field names as the spreadsheet. I've read several postings on here
but can't seem to get the coding down. I keep getting an error ont he first
line "user-defined type not defined". Below is the code I got from a
different posting here.
Any help is appreciated. Thanks.

Dim con As New adodb.Connection
Dim strcon As String
Dim strSQL As String

strcon = "Provider=Microsoft.Jet.OLEDB.4.0;"
strcon = strcon & "Data Source=U:\MY_CB_LOG1.mdb"
strcon = strcon & Persist Security Info=False"

con.Open strcon

strSQL = "INSERT INTO tbl_MAIN_CB_LOG "
strSQL = strSQL & "SELECT * FROM [Excel 8.0;Database=U:\MY_CB_LOG.xls].
[CB_DATA$]"

con.Execute strSQL

Set con = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top