Login screen validation error

M

Mr.Kane

Here si my dilemma:

I am creating a login screen for a small Access based app.
There is a combobox control where a user can select their name
and then they are required to enter a password (I have this set to a
default string currently)

The user then enables an "OK" command button whose "On Click" event
procedure is coded as the following:

Private Sub LogIn_OK_Button_Click()

Dim LogIn_ID As String
Dim Staff_ID As Single

'Check to see if data is entered into the UserName combo box
If IsNull(Me.LogIn_ID) Or Me.LogIn_ID = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.LogIn_ID.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box
If IsNull(Me.LogIn_PW) Or Me.LogIn_PW = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.LogIn_PW.SetFocus
Exit Sub
End If

'Check value of password in Staff to see if this matches value chosen
in combo box
If Me.LogIn_PW.Value = DLookup("Staff_Password", "tblStaff",
"[Staff_ID]"= "Me.LogIn_ID.Value") Then
Staff_Name = Me.LogIn_ID.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmFOCUS-PRO Login Screen", acSaveNo
DoCmd.OpenForm "frmFOCUS-PRO (Front End)"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.LogIn_PW.SetFocus
End If


End Sub

"LogIn_PW" is the password text box control
"LogIn_ID" is the Username Combobox control


When the command button is clicked it returns the message "Password
Invalid. Please Try Again"

I'm sure that I have missed something obvious in my code. The procedure
isn't comparing the correct values to hose found in my "Security" Table

"Security" Table structure:
Staff_ID Staff_Name Team_ID Staff_Password


Btw the query that is feeding the LogIn_ID combobox it's values is
SELECT DISTINCT Security_Staff.Staff_Name, Min(Security_Staff.Staff_ID)
AS MinOfStaff_ID
FROM Security_Staff
GROUP BY Security_Staff.Staff_Name
ORDER BY Security_Staff.Staff_Name;


Any help would be appreciated
 
D

Damon Heron

Your table for usernames should include a field for password. The rowsource
for the combobox would include ID, UserName, and password. Then there is no
need to check the username column because if there is no entry then there is
no password in the cbox column(2). the command button would execute this:

Private Sub cmdChkPwd_Click()
If Me.txtPwd = Me.cboLogin.Column(2) Then
curUser = Me.cboLogin.Column(0) 'curUser is a public variable that can
be used to show who logged on and what forms were accessed.
DoCmd.Close acForm, "frmFOCUS-PRO Login Screen", acSaveNo
DoCmd.OpenForm "frmFOCUS-PRO (Front End)"
Else
If ct < 4 Then
MsgBox "Password not recognized. Try again!", vbOKOnly, "WineWorks"
ct = ct + 1
Else
DoCmd.Quit
End If

End If
End Sub
Mr.Kane said:
Here si my dilemma:

I am creating a login screen for a small Access based app.
There is a combobox control where a user can select their name
and then they are required to enter a password (I have this set to a
default string currently)

The user then enables an "OK" command button whose "On Click" event
procedure is coded as the following:

Private Sub LogIn_OK_Button_Click()

Dim LogIn_ID As String
Dim Staff_ID As Single

'Check to see if data is entered into the UserName combo box
If IsNull(Me.LogIn_ID) Or Me.LogIn_ID = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.LogIn_ID.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box
If IsNull(Me.LogIn_PW) Or Me.LogIn_PW = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.LogIn_PW.SetFocus
Exit Sub
End If

'Check value of password in Staff to see if this matches value chosen
in combo box
If Me.LogIn_PW.Value = DLookup("Staff_Password", "tblStaff",
"[Staff_ID]"= "Me.LogIn_ID.Value") Then
Staff_Name = Me.LogIn_ID.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmFOCUS-PRO Login Screen", acSaveNo
DoCmd.OpenForm "frmFOCUS-PRO (Front End)"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.LogIn_PW.SetFocus
End If


End Sub

"LogIn_PW" is the password text box control
"LogIn_ID" is the Username Combobox control


When the command button is clicked it returns the message "Password
Invalid. Please Try Again"

I'm sure that I have missed something obvious in my code. The procedure
isn't comparing the correct values to hose found in my "Security" Table

"Security" Table structure:
Staff_ID Staff_Name Team_ID Staff_Password


Btw the query that is feeding the LogIn_ID combobox it's values is
SELECT DISTINCT Security_Staff.Staff_Name, Min(Security_Staff.Staff_ID)
AS MinOfStaff_ID
FROM Security_Staff
GROUP BY Security_Staff.Staff_Name
ORDER BY Security_Staff.Staff_Name;


Any help would be appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top