简单的登录程序,请大家帮帮忙
Option Explicit
Dim cnt As Integer '记录确定次数
Private Sub Command1_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
If Trim(txtuser.Text) = "" Then '判断输入的用户名是否为空
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else
sql = "select * from 密码表 where 用户名='" & txtuser.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else '检验密码是否正确
If Trim(rs_login.Fields(1)) = Trim(txtpwd.Text) Then
userID = txtuser.Text
userpow = rs_login.Fields(2)
rs_login.Close
Unload Me
Form1.Show
Else
MsgBox "密码不正确", vbOKOnly + vbExclamation, ""
txtpwd.SetFocus
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
Exit Sub
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim connectionstring As String
connectionstring = "provider=Microsoft.Jet.oledb.4.0;" & _
"data source=book.mdb"
conn.Open connectionstring
cnt = 0
End Sub
数据库是access,程序要和密码表里的用户密码相同。如果用户密码相符合,点确定后,要出现主界面比如MDIform1。应该改哪些部分呢?用户和密码都用的是text文档。
[解决办法]
你的代码有什么问题吗? 是你自己写的还是帖别人的?
Unload Me
MDIform1.Show
[解决办法]
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUP
[解决办法]
If Trim(rs_login.Fields(1)) = Trim(txtpwd.Text) Then userID = txtuser.Text userpow = rs_login.Fields(2) rs_login.Close Unload Me 'Form1.Show mdiform1.showElse MsgBox "密码不正确", vbOKOnly + vbExclamation, "" txtpwd.SetFocusEnd If