求VB高手指点一段程序

来源:百度知道 编辑:UC知道 时间:2024/05/05 01:05:09
Private Sub Command1_Click()
txtSQL = "select * from user_Form 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
miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub

以上是一个登陆窗体的代码,每次不管密码输入正确与否都会进入主界面很是疑惑,请高手指点以下,应该怎么该才能让只有密码对的情况下,进入!

按照你的思路,可以修改成这样:
Private Sub Command1_Click()
txtSQL = "select * from user_Form where user_ID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Or mrc.BOF Then '判断记录为空集时用 mrc.EOF Or mrc.BOF 请注意。
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
miCount = miCount + 1
Else
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
'这里是登陆验证通过吧
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
miCount = 0
Exit Sub
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
txtPassword.Text = ""
miCount = miCount + 1
End If
End If
If miCount = 3 Then
msgbox "您已经超过最大登陆次数,请核对后重新登陆"
miCount = 0
Me.Hide
End If
End Sub