试试:
Public IfConnectionDataBase As Boolean
Public IfAddRecordset As Boolean
'''''''''''''''''''连接数据库''''''''''''''''''''''
Public Function LinkDataBase(LinkString As String, UserName As String, PassWord As String) As Connection
Dim Cnn As New Connection
On Error GoTo ProcError
Screen.MousePointer = 11
' Cnn.Mode = adModeRead
Cnn.Open LinkString, UserName, PassWord
Set LinkDataBase = Cnn
IfConnectionDataBase = True
Screen.MousePointer = 0
ProcExit:
Exit Function
ProcError:
Screen.MousePointer = 0
MsgBox "错误号:" & Err.Number & vbCrLf & Err.Description & "!", 48, "连接错误提示"
IfConnectionDataBase = False
Resume ProcExit
End Function
'''''''''''''''''''''''''添加记录''''''''''''''''''''''''''''
Public Sub AddNewRecordset(LinkString As String, UserName As String, PassWord As String, TableName As String, _
FieldName As String, FieldValues As String)
Dim SQL As String
Dim Cnn As New Connection
On Error GoTo ProcError
Screen.MousePointer = 11
SQL = " insert into " & TableName & " ( " & FieldName & " ) values ( " & FieldValues & " )"
Set Cnn = LinkDataBase(LinkString, UserName, PassWord)
' MsgBox SQL
Cnn.Execute SQL
IfAddRecordset = True
Screen.MousePointer = 0
ProcExit:
Exit Sub
ProcError:
Screen.MousePointer = 0
MsgBox "错误号:" & Err.Number & vbCrLf & Err.Description & "!", 48, "添加记录错误提示"
IfAddRecordset = False
Resume ProcExit
End Sub