我在VB(Excel 10)上收到以下运行时错误“微软访问数据库引擎无法找到该对象”。 “数据库”是在工作表中命名的定义,但它不会提取它。任何想法将非常感谢!!
Sub ConnectDB()
If cnn.State <> adStateOpen Then
Dim strFileName As String
strFileName = "O:Children's Fund\APS 2014-15\Refrerral - Allocation Database.xlsx"
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strFileName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"";"
End If
End Sub
Sub CopyData()
ConnectDB
Dim rst As New ADODB.Recordset
Dim CurrentID As Long
Dim vbResult As VbMsgBoxResult
rst.Open "SELECT * FROM [A2:M1000];", cnn, adOpenStatic, adLockReadOnly
If Not rst.EOF Then
rst.MoveLast
CurrentID = rst("RefNumber")
CurrentID = CurrentID + 1
Else
CurrentID = 1
End If
Dim sql As String
sql = "Insert into [Database] (refnumber, surname, FirstName, DOB, ReferrerEmail, PreferredSetting, MotherEmployment, FatherEmployment, OtherEmployment, Other1Employment, Attendance, Exclusions) values ('" & _
CurrentID & "','" & [FormSurname] & "','" & [FormFirstName] & "','" & [FormDOB] & "','" & [FormEmail] & "','" & [FormPreferred] & "','" & [FormMother] & "','" & [FormFather] & "','" & [FormOther] & "','" & [FormOther1] & "','" & [FormAttendance] & "','" & [FormExclusions] & "')"
cnn.Execute (sql)
MsgBox "Record Saved to Database"
DisconnectDB
End Sub
Sub DisconnectDB()
If cnn.State <> adStateClosed Then
cnn.Close
Set cnn = Nothing
End If
End Sub
非常感谢
萨姆