K
keithl816
Hello everybody,
I hope someone can help me with this problem, I got the code below from
this website.
http://www.erlandsendata.no/english/index.php?t=envbadac
I'm trying to send data to an access table already created in a access
db. I followed the instructions on this site and still can't seem to
make it work. Where am I supposed to place this code? I tried right
clicking the sheet tab in excel and placing it in the sheet code that
the info is appearing on but it did not work. I also tried placing it
in a module. Still doesn't work.
Code:
--------------------
Sub ADOFromExcelToAccess()
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\monthly report\boomaxedb.mdb;"
Set rs = New ADODB.Recordset
rs.Open "boomaxedb", cn, adOpenKeyset, adLockOptimistic, adCmdTable
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
.AddNew
.Fields("date") = Range("A" & r).Value
.Fields("operator") = Range("B" & r).Value
.Fields("name of road") = Range("C" & r).Value
.Fields("distance") = Range("d" & r).Value
.Update
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
--------------------
The data is stored in excel workbook named monthly report it is located
in a folder named Monthly, the access table is named boomaxedb. it is
located in the same folder.
I also clicked on the tools in vbe and reference and checked the box
next to microsoft activexdata objects 2.6 library.
Thanks in advance,
Larry
I hope someone can help me with this problem, I got the code below from
this website.
http://www.erlandsendata.no/english/index.php?t=envbadac
I'm trying to send data to an access table already created in a access
db. I followed the instructions on this site and still can't seem to
make it work. Where am I supposed to place this code? I tried right
clicking the sheet tab in excel and placing it in the sheet code that
the info is appearing on but it did not work. I also tried placing it
in a module. Still doesn't work.
Code:
--------------------
Sub ADOFromExcelToAccess()
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\monthly report\boomaxedb.mdb;"
Set rs = New ADODB.Recordset
rs.Open "boomaxedb", cn, adOpenKeyset, adLockOptimistic, adCmdTable
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
.AddNew
.Fields("date") = Range("A" & r).Value
.Fields("operator") = Range("B" & r).Value
.Fields("name of road") = Range("C" & r).Value
.Fields("distance") = Range("d" & r).Value
.Update
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
--------------------
The data is stored in excel workbook named monthly report it is located
in a folder named Monthly, the access table is named boomaxedb. it is
located in the same folder.
I also clicked on the tools in vbe and reference and checked the box
next to microsoft activexdata objects 2.6 library.
Thanks in advance,
Larry