Hello,
I was wondering if anyone could help me with my following code.
I currently have 3 user groups (Admin/User/Guest[read only]) and depending on who is logged in i want to be able to restrict what they can do.
Below is my login control:
Code:
Option Compare Database
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 User Name", vbInformation, "Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
Else
'open different form according to user level
If UserLevel = 1 Then ' for Admin
DoCmd.OpenForm "Raw Material Database"
Else
If UserLevel = 2 Then ' for Users
DoCmd.OpenForm "Raw Material Database"
Else
If UserLevel = 3 Then ' for Guests
End If
End If
End If
End If
End If
End If
End Sub
Private Sub cmdLogin_Click()
End Sub
Private Sub Form_Load()
Me.txtUserName.SetFocus
End Sub
This works fine however i want it so on my database form that edits are restricted to the Admin/User only so im trying to get the following code to work on my form.
Code:
Option Compare Database
Private Sub Form_Load()
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 Forms!frmLogin!UserLevel = 1 Then
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletes = True
Else
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletes = False
End If
End Sub
However i am not sure how to sort that code so it works.
Any help would be highly appricated.
Thanks