bpascal123
New member
- Local time
- Today, 15:10
- Joined
- Oct 29, 2011
- Messages
- 3
Hi cyberspace,
I'm still in the process of learning excel and access. I'd like to send data from excel 2003 to access 2003. I have found in the Excel forum a few discussions similar to this one although the code looks like what I'm posting, I'd like my code to run from Excel. What I have found here was a code that would run from Access :
access-programmers.co.uk/forums/showthread.php?t=211039&highlight=send+data+from+excel+to+access
So, I have downloaded an access template on the msdn site and i'm using this to learn. So far, I'm able to retrieve data from Access and SQL Server Denali through sql queries. I'm using Microsoft Active X data objects 6.0 library.
I don't know what's wrong but nothing happens when making this code run...
Option Explicit
Sub Send2Access()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open "Provider=Microsoft.jet.OLEDB.4.0;data source =
G:\code_access\access templates\PurchaseOrders.mdb;"
rs.Open "Suppliers", cn, adOpenKeyset, adLockOptimistic, adCmdTable
r = 2
Do While Len(Range("A" & r).Formula) > 0
With rs
.AddNew
.Fields("ContactTitle") = Range("A" & r).Value
.Fields("Address City") = Range("A" & r).Value
.Fields("PostalCode") = Range("A" & r).Value
.Fields("StateOrProvince") = Range("A" & r).Value
.Fields("Country") = Range("A" & r).Value
.Fields("PhoneNumber") = Range("A" & r).Value
.Fields("FaxNumber") = Range("A" & r).Value
.Fields("PaymentTerms") = Range("A" & r).Value
.Fields("EmailAddress") = Range("A" & r).Value
.Fields("Notes") = Range("A" & r).Value
.Update
End With
r = r + 1
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Hope to get some help for this
cyberuser Pascal
I'm still in the process of learning excel and access. I'd like to send data from excel 2003 to access 2003. I have found in the Excel forum a few discussions similar to this one although the code looks like what I'm posting, I'd like my code to run from Excel. What I have found here was a code that would run from Access :
access-programmers.co.uk/forums/showthread.php?t=211039&highlight=send+data+from+excel+to+access
So, I have downloaded an access template on the msdn site and i'm using this to learn. So far, I'm able to retrieve data from Access and SQL Server Denali through sql queries. I'm using Microsoft Active X data objects 6.0 library.
I don't know what's wrong but nothing happens when making this code run...

Option Explicit
Sub Send2Access()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open "Provider=Microsoft.jet.OLEDB.4.0;data source =
G:\code_access\access templates\PurchaseOrders.mdb;"
rs.Open "Suppliers", cn, adOpenKeyset, adLockOptimistic, adCmdTable
r = 2
Do While Len(Range("A" & r).Formula) > 0
With rs
.AddNew
.Fields("ContactTitle") = Range("A" & r).Value
.Fields("Address City") = Range("A" & r).Value
.Fields("PostalCode") = Range("A" & r).Value
.Fields("StateOrProvince") = Range("A" & r).Value
.Fields("Country") = Range("A" & r).Value
.Fields("PhoneNumber") = Range("A" & r).Value
.Fields("FaxNumber") = Range("A" & r).Value
.Fields("PaymentTerms") = Range("A" & r).Value
.Fields("EmailAddress") = Range("A" & r).Value
.Fields("Notes") = Range("A" & r).Value
.Update
End With
r = r + 1
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Hope to get some help for this

cyberuser Pascal