帮我解决vb中的数据连接问题 公用模块为什么老是提示我错误啊

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$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
"query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
'rst.Movelast '»ñµÃRecordcountÖµ
Set ExecuteSQL = rst
MsgString = "查询到& rst.RecordCount & _
" 条记录"
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误" & _
Err.Description
Resume ExecuteSQL_Exit
End Function
——————————————————
Public Function ConnectString() As String
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\vb\datebase\db1.mdb;Persist Security Info=False"
End Function
——————————————————
以上是公用模块的,下面是登录窗口的
————————————————————
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim Msgtext As String
username = ""
If Trim(txtusername.Text = "") Then
MsgBox "用户名不能为空", vbOKOnly + vbExclamation, "警告"
txtusername.SetFocus
Else
txtSQL = "select * from user where username = '" & txtusername.Text & "'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)————这里提示对象变量或with块变量未设置

If mrc.EOF = True Then
MsgBox "没有这个用户¡", vbOKOnly + vbExclamation, "警告"
txtusername.SetFocus
Else
If Trim(mrc.Fields(1)) = Trim(txtpassword.Text) Then
ok = True
mrc.Close
Me.Hide
username = Trim(txtusername.Text)
Else
MsgBox "密码不对¡", vbOKOnly + vbExclamation, "警告"
txtpassword.SetFocus
txtpassword.Text = ""
End If
End If
End If
micount = micount + 1
If micount = 3 Then
Me.Hide
End If
Exit Sub
End Sub

谁知道帮帮我吧,谢谢啊,解决不了啊,晕
高手都哪去了?越详细越好,是不是我其他的哪地方做的不对啊?

你那里错了...所以提示....
至于代码我不是太熟悉...
我只能告诉你的是,你的那里熟错了,别望了,标点符号,和英文字母,错一个都不能正常运行....
温馨提示:答案为网友推荐,仅供参考
相似回答