Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write Excel data to Access 2007

Status
Not open for further replies.

medric2

MIS
Mar 18, 2003
24
GB
Hi
I'm trying to write data from Excel 2007 to An Access 2007 database. I have tried code which is designed for an Access 97/2002 database and it does not work with Access 2007. At least I think it's the code. The same code works OK with an Access 97 database but I get an error saying that the database format is not recognized when I try an Access 2007 database.
Does anyone have code for the 2007 version please.
 



Hi,

Please post the code you currently have.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip

Here is the code

Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=H:\DataBase1.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Jobfiles", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("PRODUCT") = Range("A" & r).Value
.Fields("CUSTOMER") = Range("B" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
 
I've found the problem.

My connection string needs to be changed from Jet.OLEDB.4.0 to ACE.OLEDB.12.0 and it works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top