VB实时错误91:对象变量或With块变量未设置
'强制变量声明OptionExplicitPublicOKAsBoolean'记录确定次数DimmiCountAsIntegerDimUserNameAsStringPr...
'强制变量声明
Option Explicit
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Dim UserName As String
Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
'用来存放SQL语句
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_info where user_ID = '" & txtUserName.Text & "'"
'执行查询语句
Set mrc = ExecuteSQL(txtSQL, MsgText)
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
Private Sub Form_Load()
OK = False
miCount = 0
End Sub 展开
Option Explicit
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Dim UserName As String
Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
'用来存放SQL语句
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_info where user_ID = '" & txtUserName.Text & "'"
'执行查询语句
Set mrc = ExecuteSQL(txtSQL, MsgText)
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
Private Sub Form_Load()
OK = False
miCount = 0
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询