Hi,
I have created a custom Login Form.
The user selects there name from a combo box and enters there password.
The username and password are checked and if they are correct the user is directed to a form based on there clearance.(i.e. User level security)
The problem...
I am trying to create a "dashboard" where the user can only see their own information. I.e. there login in details, personnal info and there current clients(the clients are being shown in a sub-form).
The problem I am having is that whenever I login with the user, the form opens and a new record is added to the user table.
Is there anyway to stop this happening, what am I doing wrong?
I have been searching through posts for ages but I cannot seem to find a solution.
The code that is running on the "Login" button on the login form:
Code:
Private Sub cmdlogin_Click()
Dim intanswer As Integer
Dim intLogonAttempts As Integer
Dim intSec As Recordset
Dim openargs As Variant
Dim Name As String
Name = "[UserName]=" & Chr(34) & Me.cboEmployee & Chr(34)
openargs = Me.cboEmployee.Value
Set intSec = CurrentDb.OpenRecordset("tblUserDetails", dbOpenDynaset)
intSec.FindFirst "[UserName]=" & Chr(34) & Me.cboEmployee & Chr(34)
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.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
If Me.txtPassword.Value = DLookup("Password", "tblUserDetails", _
"[UserName]='" & Me.cboEmployee.Value & "'") Then
Select Case intSec![SecurityClearance]
Case 1
DoCmd.Close acForm, "frmlogin", acSaveNo
DoCmd.OpenForm "frmadmin"
Forms!frmadmin.Filter = Name 'only show records belonging to logged in user
Forms!frmadmin.FilterOn = True
Forms!frmadmin!EmployeeID = Me.cboEmployee.Column(1)
Case 3
DoCmd.Close acForm, "frmlogin", acSaveNo
DoCmd.OpenForm "frmadmin"
DoCmd.OpenForm "frmpartner"
Case 5
DoCmd.Close acForm, "frmlogin", acSaveNo
DoCmd.OpenForm "frmadmin"
DoCmd.OpenForm "frmManager"
End Select
'''Error message if username and password do not match
Else
intanswer = MsgBox("You have entered an incorrect Password" & vbNewLine & "Do you wish to try again?", vbQuestion + vbYesNo, "Login Error")
If intanswer = vbYes Then
Me.txtPassword.SetFocus
Else
Application.Quit acQuitSaveAll
End If
End If
intSec.Close
Set intSec = Nothing
End Sub
Any help will be really appreciated, please feel free to ask any questions.
I have attached the database, the form in question is "Loginform".
The password for all the users is 12345.
Thanks in advance.