我来说两句
:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
Me.Data1.DatabaseName = App.Path & "\数据库名.MDB"
Me.Data1.RecordSource = " SELECT * FROM 表名"
Me.Data1.Refresh
If Data1.Recordset.RecordCount = 0 Then
Data1.Recordset.AddNew
Data1.Recordset.Update
End If
Data1.Recordset.MoveFirst
If Data1.Recordset("**") = False Then
frm表.Show 1
Me.Data1.Refresh
Me.Data1.Recordset.MoveFirst
End If
Data1.Refresh
wxyname = Data1.Recordset("姓名")
wxypassword = Data1.Recordset("密码")
txtUserName.Text = wxyname
End Sub
Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
'ToDo: 创建测试密码是否正确
'检查正确密码
If Trim(txtPassword.Text) = Trim(wxypassword) Then
OK = True
Me.Hide
frmMain.Show
Else
MsgBox "密码错误,再试一次!", , "登录"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
End If
End Sub
同时再掉用点东西!
多用户登录
Private Sub cmdOk_Click()
Dim strUserPass As String
'判断用户是否已经输入用户名和密码
golUsername = Trim(txtName.Text)
strUserPass = Trim(txtPass.Text)
If golUsername = "" Then
MsgBox "请输入用户名", vbExclamation, "登录提示"
txtName.SetFocus
Exit Sub
End If
If strUserPass = "" Then
MsgBox "请输入密码", vbExclamation, "登录提示"
txtPass.SetFocus
Exit Sub
End If
'判断用户登录信息是否正确
sRs.Open "select * from TAB_User where 用户名='" & golUsername & "'", sCon, adOpenStatic, adLockOptimistic
If sRs.EOF Then
MsgBox "没有此用户", vbCritical, "登录错误"
txtName.SelStart = 0
txtName.SelLength = Len(txtName.Text)
txtName.SetFocus
sRs.Close
Exit Sub
End If
sRs.Close
sRs.Open "select * from TAB_User where 用户名='" & golUsername & "' and 用户密码='" & strUserPass & "'", sCon, adOpenStatic, adLockOptimistic
If sRs.EOF Then
MsgBox "密码错误", vbCritical, "登录错误"
txtPass.SelStart = 0
txtPass.SelLength = Len(txtPass.Text)
txtPass.SetFocus
sRs.Close
Exit Sub
End If
sRs.Close
ExecuteCommand "update TAB_user set 最近登录时间=#" & Now & "# where 用户名='" & golUsername & "'"
MDIFormMain.Show
Unload Me
End Sub
Option Explicit
Dim User As String 'UserNo存放用户编号
Dim Pass As String 'Password存放用户密码
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\PASS.MDB"
Data1.RecordSource = "PASS"
End Sub
Private Sub cmdOK_Click()
User = Text1.Text
Pass = Text2.Text
Data1.Recordset.FindFirst " UserNo = '" & User & "'"
If Data1.Recordset.NoMatch Then
MsgBox "用户名输入错误!"
Exit Sub
Else
If Data1.Recordset!Password <> Pass Then
MsgBox "密码输入错误!"
Exit Sub
End If
End If
End Sub