I would appreciate if someone would help me with this.
I am using Access 2007. My boss has given me a project to create a tool for our team. I'm done with most part of the project, but for the last part I want editing and updating of database restricted to a few members of our team. However others can access the database and run queries etc. through buttons on a form.
I went about creating a login form for users to get access to the database and in turn created a table with fields UserID, UserName, UserPW and a yes/no field titled IsAdmin. For those who would be limited access would log in as 'Other' user and same as password. I am then using the code to determine if the user should be treated as admin or not by looking up the IsAdmin field in the table. Following is what I have so far, but it needs correction some places and I can't figure where:
Private Sub cmdLogin_Click()
Dim xxAdmin As String
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboUser) Or Me.cboUser = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboUser.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in RATusers table to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("UserPW", "RATusers", "[UserID]=" & Me.cboUser.Value) Then
MyUserID = Me.cboUser.Value
'Close logon form and open main form
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "Audit Tool Summary"
xxAdmin = DLookup("IsAdmin", "RATusers", "[UserID]=" & Me.cboUser.Value)
If xxAdmin = 1 Then
Me.AllowEdits = False
Me.AllowLayoutView = False
End If
Else
MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Please can someone help me with this? Programming is not my cup of tea
I am using Access 2007. My boss has given me a project to create a tool for our team. I'm done with most part of the project, but for the last part I want editing and updating of database restricted to a few members of our team. However others can access the database and run queries etc. through buttons on a form.
I went about creating a login form for users to get access to the database and in turn created a table with fields UserID, UserName, UserPW and a yes/no field titled IsAdmin. For those who would be limited access would log in as 'Other' user and same as password. I am then using the code to determine if the user should be treated as admin or not by looking up the IsAdmin field in the table. Following is what I have so far, but it needs correction some places and I can't figure where:
Private Sub cmdLogin_Click()
Dim xxAdmin As String
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboUser) Or Me.cboUser = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboUser.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in RATusers table to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("UserPW", "RATusers", "[UserID]=" & Me.cboUser.Value) Then
MyUserID = Me.cboUser.Value
'Close logon form and open main form
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "Audit Tool Summary"
xxAdmin = DLookup("IsAdmin", "RATusers", "[UserID]=" & Me.cboUser.Value)
If xxAdmin = 1 Then
Me.AllowEdits = False
Me.AllowLayoutView = False
End If
Else
MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Please can someone help me with this? Programming is not my cup of tea