问题描述
我一直在自学适用于应用程序的Microsoft VBA,并且到达了一个真正需要帮助的地方。我有一个登录表单,该表单通过根据分配的角色打开特定的表单来控制访问。一切正常,但允许一个人查看所有成员记录。我试图将“表单”限制为已登录的用户。以下是我用于登录的代码。
Private Sub Command1_Click()
Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim Username As String
Dim TempID As String
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName",vbInformation,"Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password","Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin","Users","UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUername.Value
Username = DLookup("[UserName]","[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserType]","[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]","[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLogin = DLookup("[UserLogin]","[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password","New password required"
DoCmd.OpenForm "frmUserinfo","[UserLogin] = " & UserLogin
Else
'Open different form according to user level
If userLevel = 1 Then 'For Admin
DoCmd.OpenForm "Training"
Else
'For Trainee
DoCmd.OpenForm "Form",acNormal,"ID = & TempID 'TempID finds the lastname from UserLogin and I need the number from UserName
End If
End If
End If
End Sub
打开的“表单”具有一个组合框,用于控制显示哪些记录。如何获取登录的用户信息,以基于UserName传递给“表单”?如果那是正确的方法!谢谢大家的帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)