看我的吧:
Private Sub CmdOK_Click()
Dim connectionstring As String
connectionstring = "provider=Microsoft.Jet.oledb.4.0;" & _
"data source=archive.mdb"
conn.Open connectionstring
cnt = 0
End Sub
Private Sub Command1_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(Text1.Text) = "" Then '判断输入的用户名是否为空
MsgBox "请填写用户名", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Else
sql = "select * from 系统信息 where user_ID='" & Text1.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Else '检验密码是否正确
If Trim(rs_login.Fields(1)) = Trim(Text2.Text) Then
userID = Text1.Text
username = rs_login.Fields(2)
rs_login.Close
Unload Me
frmmain.Show
Else
MsgBox "密码不正确", vbOKOnly + vbExclamation, ""
Text2.SetFocus
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
End Sub
看一下下面这个例子吧:
Private Sub cmdok_Click() cmdok 就是登录对话框中的确认按钮
If txtpassword.Text <> "密码" Then '如果密码不对就显示提示
MsgBox "你的密码不正确,请重新输入!"
txtpassword.Text = "" '清空密码框中的文本,让用户重新输入
txtpassword.SetFocus '焦点设在密码框中
Else
MsgBox "密码正确,欢迎你使用本系统!" '密码正确就显示此提示
End If
End Sub