我有以下ado連接從excel訪問,但它不起作用,我得到上述錯誤。有任何想法嗎?ADO執行 - 編譯錯誤:用戶定義類型未定義
Sub ADO_to_access()
Dim database As New ADODB.Connection // ERROR HERE
Dim connectionstring As String
Dim NewSet As Recordset
Dim CurrentSheet As Worksheet
Set CurrentSheet = ActiveSheet
Set objaccess = Nothing
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Users\Carlos\Desktop\VBA - CW - Database.mdb;"
database.Open connectionstring
' ************* MEN
Set NewSet = New ADODB.Recordset
NewSet.Open "Mens_Dept_Data", database, adOpenKeyset, adLockOptimistic, adCmdTable
x = 6
Do While Len(Range("P" & x).Formula) > 0
With NewSet
.AddNew
.Fields("Irina").Value = CurrentSheet.Range("P" & x).Value
.Fields("Thomas").Value = CurrentSheet.Range("Q" & x).Value
.Fields("Jackie").Value = CurrentSheet.Range("R" & x).Value
.Update
End With
x = x + 1
Loop
NewSet.Close
database.Close
End Sub
順便說一句,在SO上的代碼格式有一個錯誤。爲了避免這種情況,請在評論結束時「關閉」評論: -/ – 2010-11-19 14:41:32