判断是否为管理员?
Private Sub cmdOK_Click()On Error GoTo errh:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set rs = cn.Execute("SELECT UserName , Password FROM 超级用户 ")
If rs.EOF Then
rs.Close
Set rs = Nothing
Unload Me
Load FrmMain
Exit Sub
End If
rs.MoveFirst
Dim i As Integer
'校验是否为超级用户
Do
If rs.Fields("UserName") = txtUserName.Text Then
If rs.Fields("Password") = txtPassword.Text Then
UserType = True
LoginSucceeded = True
rs.Close
If txtPassword.Text = "Admin" Then IsAdmin = True
Unload Me
Load FrmMain
Exit Sub
Exit Do
End If
End If
rs.MoveNext
Loop Until rs.EOF
'校验是否为普通用户
Set rs = cn.Execute("SELECT 学号 FROM 学生 WHERE 学号 =" & "'" & txtPassword.Text & "'")
If rs.EOF Then
MsgBox "无效密码或用户名请重试!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
Else
rs.Close
UserType = False
LoginSucceeded = True
Unload Me
Load FrmMain
End If
Exit Sub
errh:
MsgBox Err.Description
End Sub
-----------------------------------------------------------------------
假如以上代码是登陆代码,如果登陆的是amin管理员,那么主界面的cmd1按钮就被激活(cmd1.enable=true),否则不被激活。
UserType变量怎样定义,在登陆窗口定义?公用? 在主界面的from-load()里可以直接使用嘛?