我用VB做的人事管理系统,有个错误“对象变量或with块变量未设置”是怎么回事啊?

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:01:21
这是我的代码
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim rstLogin As ADODB.Recordset
Dim flag As String
gUserName = ""
gUserKind = ""
If Trim(txtUserName.Text = "") Then
MsgBox "用户名不能为空!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from tbUser where UserId = '" & txtUserName.Text & "'"
flag = ExecuteSQL(txtSQL, rstLogin, False)
If rstLogin.EOF = True Then
MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(rstLogin.Fields(1)) = Trim(txtPassword.Text) Then
gUserName = Trim(txtUserName.Text)
gUserKind = Trim(rstLogin.Fields(2))
gLoginSucceeded = True
rstLogin.Close
Me.Hide
frmMain.Show
Else

把 ExecuteSQL 的代码贴出来看看

你前面flag = ExecuteSQL(txtSQL, rstLogin, False)这句不是执行txtSQL并将记录集返回给rstLogin,把ExecuteSQL这个函数的代码贴出来看看,应该是这个函数没有执行成功。
或者在flag = ExecuteSQL(txtSQL, rstLogin, False)这句下面判断一下rstLogin是不是nothing,应该是nothing,判断的方法是
if rstLogin is noting then
msgbox "nothing"
end if
如果是nothing说明问题出在ExecuteSQL这个函数中。