Public Function executesql(ByVal sql As String, msgstring As String) As adodb.Recordset
Dim cnn As adodb.connection
Dim rst As adodb.Recordset
Dim stokens() As String
On Error GoTo executesql_error
stokens = Split(sql)
Set cnn = New adodb.connection
cnn.open connectstring
If InStr("insert,delete,update", UCase$(stoken(0))) Then
cnn.execute sql
msgstring = stokens(0) & "query successful"
Else
Set rst = New adodb.Recordset
rst.open (sql), cnn, adopenkeyset, adlockoptimistic
Set executesql = rst
msgstring = "查询到"& rst.recordcount & "条记录"
End If
executesql_exit:
Set rst = Nothing
Set cnn = Nothing
End Function
executesql_error:
msgstring = "查询错误:" & Err.Description
Resume executesql_exit
End Function
调试时老是说:"用户未自定义对象(代码中的红色段)",接着下面程序还用到的变量executesql也就还说:"用户未自定义对象",请大家帮忙!!!