error when connecting to access 2007

S

sam

I am not able to connect to access 2007. IT gives me a compile error msg:
"User-defined type not Defined"

Here is my code:

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider = Microsoft.ACE.OLEDB.12.0" & _
"Data Source=C:\Documents and Settings\My
Documents\Demo_Folder\Demo.accdb;"

' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Sheet1", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 2 ' 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
.Fields("Officer_Name") = Range("A" & r).Value
.Fields("Account") = Range("C" & r).Value
.Fields("Officer_Phone") = Range("D" & r).Value
.Fields("Contact_Person_Name") = Range("E" & r).Value
.Fields("Contact_Person_Phone") = Range("F" & r).Value
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

Thanks in Advance
 

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