用vb,access做一个登陆界面。

来源:百度知道 编辑:UC知道 时间:2024/05/10 12:30:25
要用vb连接access做一个登陆界面。数据库名:db1,表名:登录表。确定按钮:cmd_ok 取消按钮:cmd_cancel。 用户名文本框:txtuser,密码文本框是:txtpwd。
要求:输入用户名和密码都正确,则进入“主窗体”,否则出现提示信息。

急用!非常感谢各位高手作答!!

Private Sub Cmd_ok()
On Error Resume Next
Dim Psw As String
If txtuser = "" Or txtpwd = "" Then
MsgBox "用户名密码不能为空,请重新输入!", 64, "提示"
Else
Adodc1.RecordSource = "select * from 登录表 where admin ='" & txtuser.Text & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Psw = Adodc1.Recordset.Fields("Password")
If txtpwd.Text = Psw Then
main.Show: Unload Me
ElseIf txtpwd <> Psw Then
MsgBox "密码错误,请重新输入!", 64, "提示": txtpwd = "": txtpwd.SetFocus
End If
Else
MsgBox "没有该用户!", 64, "提示": txtuser = "": txtuser.SetFocus: txtpwd = ""
End If
End If
End Sub

Private Sub Cmd_cancel()
End
End Sub

Private Sub Form_Load()
Adodc1.Connec