Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel export to Access

I need to export data on my excel sheet1.
Sheet1 is a hidden worksheet.
I want to create a command button in my sheet2 that will export
data on sheet1 to an existing Access database table.
I made it so that field name on my sheet1 is the same as the Access table
being
imported to.
Can someone help me with the code?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Excel export to Access

Here is the code.
Please add a reference to Microsoft ActiveX Data Object

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=C:\MWCI\Database\Dbase.mdb;"
strcon = strcon & Persist Security Info=False"

con.Open strcon

strSQL = "INSERT INTO TABLE1 "
strSQL = strSQL & "SELECT * FROM [Excel
8.0;Database=C:\book1.xls].[Sheet1$]"

con.Execute strSQL

set con = nothing


replace Table1 with the name of your table
in MsAccess same with the
Database=C:\book1.xls
Data Source=C:\MWCI\Database\Dbase.mdb
Sheet1

Hope this will help u.

Arthur

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel export to Access

Thank you Arthur.

I've tried this, but could not get it to work.
I really do not know much about codes, although I'm trying to learn and
figure this out.

Would it be possible to explain like you would explain to a dummy?


" wrote:

Here is the code.
Please add a reference to Microsoft ActiveX Data Object

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=C:\MWCI\Database\Dbase.mdb;"
strcon = strcon & Persist Security Info=False"

con.Open strcon

strSQL = "INSERT INTO TABLE1 "
strSQL = strSQL & "SELECT * FROM [Excel
8.0;Database=C:\book1.xls].[Sheet1$]"

con.Execute strSQL

set con = nothing


replace Table1 with the name of your table
in MsAccess same with the
Database=C:\book1.xls
Data Source=C:\MWCI\Database\Dbase.mdb
Sheet1

Hope this will help u.

Arthur


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Excel export to Access


Goto ViewsToolbarsControl Toolbox then
In sheet2 of your workbook
add a command button then double click that button.
You will be directed to Visual basic editor.

Copy and paste this code inside the "Private Sub
CommandButton1_Click()"

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=C:\db1.mdb;"
strcon = strcon & "Persist Security Info=False"


con.Open strcon


strSQL = "INSERT INTO TABLE1 "
strSQL = strSQL & "SELECT * FROM "
strSQL = strSQL & "[Excel 8.0;Database=C:\book1.xls].[Sheet1$]"


con.Execute strSQL


Be sure to replace the
Database=C:\book1.xls,
Data Source=C:\db1.mdb
TABLE1

Finally, RUN the code by pressing F5

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel export to Access

Arthur,

Thank you.
I tried it but am still getting an error message:

Run-time error '-2147217913 (80040e07)':
Data type mismatch in criteria expression.

And in the vba screen, con.Execute strSQL is hi-lighted yellow with a
yellow arrow to it.

I'm sorry to be a pain, hope you will help me.

Thank you

" wrote:


Goto ViewsToolbarsControl Toolbox then
In sheet2 of your workbook
add a command button then double click that button.
You will be directed to Visual basic editor.

Copy and paste this code inside the "Private Sub
CommandButton1_Click()"

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=C:\db1.mdb;"
strcon = strcon & "Persist Security Info=False"


con.Open strcon


strSQL = "INSERT INTO TABLE1 "
strSQL = strSQL & "SELECT * FROM "
strSQL = strSQL & "[Excel 8.0;Database=C:\book1.xls].[Sheet1$]"


con.Execute strSQL


Be sure to replace the
Database=C:\book1.xls,
Data Source=C:\db1.mdb
TABLE1

Finally, RUN the code by pressing F5




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Excel export to Access

please download this sample files

http://www.sharebigfile.com/download.php?id=23EFC5A2

extract that zip file to C:\ directory


About the error you encounter, i guess it has something to do with
the field type of the access table. Maybe you are saving a string to
integer type field.

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
excel pivot export to access andriil Excel Programming 1 July 26th 07 01:10 PM
Export to Access from Excel Secret Squirrel Excel Discussion (Misc queries) 0 February 7th 06 11:44 PM
Export from Access to Excel tamxwell Excel Programming 9 June 30th 05 08:31 PM
export access to excel. change access & update excel at same time fastcar Excel Discussion (Misc queries) 0 June 24th 05 09:27 PM
Export from Access to Excel Sabina Excel Discussion (Misc queries) 3 February 23rd 05 09:56 PM


All times are GMT +1. The time now is 03:28 PM.

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

About Us

"It's about Microsoft Excel"