Solved

How alter onclick event of code for first time login

Posted on 2014-01-20
2
429 Views
Last Modified: 2014-01-20
I have the following code in an onclick event of a login form.  But I need to alter it so that in the event the user is logging in for the first time they will be taken to a separate form to enter their new login of choice.  Then after they have entered their new login be taken back to the original form to continue.  How do I alter the following code?

'Check to see if data is entered into the Password combo 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 tblEmployees to see if this matches value chosen in combo box
    If Me.txtPassword.Value = DLookup("Password", "tblEmployees", "[EmployeeID]=" & Me.cboName.Value) Then
       
        myempid = Me.cboName.Value

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("LOCALtblLogin")
            rs.AddNew
            rs!FullName = Me.txtFullName
            rs!EmployeeID = Me.txtLoginID
            rs!DateTime = Now()
            rs!SecurityLevel = Me.txtSecurityLevel
            rs.Update
       
'Close logon form and open splash screen
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmMainMenu"
    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
           
    DoCmd.Close
   
    DoCmd.OpenForm "frmMainMenu"
0
Comment
Question by:SteveL13
2 Comments
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39794627
This is the code module from the login button on my login form.  There are a few things I do do facilitate this.
1. I assign a default password of "Password" to each new user or when the user requests a password reset.
2. I verify the id and password and then check to see if the password is "password".  If it is, I unhide a new password control and confirm password control.
3. I set a hidden field on the form so I know I am in this "new password" process.
4. The login form is bound to the security table so I don't need DAO to update it.

I leave the login form open but not visible once the log in have been validated and I reference it from other forms to ensure that the user is authorized for various functions.

Private Sub cmdLogIn_Click()
    Dim strSQL As String
    
    On Error GoTo ErrProc
    'Determine if the combination of user ID and password are on the
    'tblSecurityUser table
        
    Me.Requery
        
    'If this is a valid userID/password combination, close this screen and open the main menu
    If Me.txtFirstName & "" <> "" Then
    Else
    'If this is not a valid userID/password combination, display error message.
        MsgBox "The User Name and Password you have entered are not valid.  Please re-enter this information or click on cancel.", vbCritical, "Security Error"
        Exit Sub
    End If
      
    'Force password change
    If Me.txtPASSWORD = "Password" Then
        If Me.chkForceChange = True Then
            If Me.txtNewPswd = Me.txtVerifyPswd Then
                If Me.txtNewPswd = "Password" Then
                    MsgBox "This is not a valid password.", vbOKOnly
                    Exit Sub
                End If
                Me.txtPASSWORD = Me.txtNewPswd
                Me.txtNewPswd.Visible = False
                Me.txtVerifyPswd.Visible = False
                Me.chkForceChange = False
                DoCmd.RunCommand acCmdSaveRecord
            Else
                MsgBox "Please reenter new password in both 'New' and 'Verify' fields.", vbOKOnly
                Me.txtNewPswd = Null
                Me.txtVerifyPswd = Null
                Me.txtNewPswd.SetFocus
                Exit Sub
            End If
        Else
            MsgBox "Please change your password.", vbOKOnly
            Me.txtNewPswd.Visible = True
            Me.txtVerifyPswd.Visible = True
            Me.chkForceChange = True
            Me.txtNewPswd.SetFocus
            Exit Sub
        End If
    Else
        If Me.chkForceChange = True Then
            If Me.txtNewPswd = Me.txtVerifyPswd Then
                If Me.txtNewPswd = "Password" Then
                    MsgBox "This is not a valid password.", vbOKOnly
                    Exit Sub
                End If
                Me.txtPASSWORD = Me.txtNewPswd
                Me.txtNewPswd.Visible = False
                Me.txtVerifyPswd.Visible = False
                Me.chkForceChange = False
                DoCmd.RunCommand acCmdSaveRecord
            Else
                MsgBox "Please reenter new password in both 'New' and 'Verify' fields.", vbOKOnly
                Me.txtNewPswd.SetFocus
                Exit Sub
            End If
        End If
    End If
    
    DoCmd.OpenForm "switchboard", acNormal, , , acFormReadOnly, acWindowNormal
    Me.Visible = False
            
ExitProc:
    DoCmd.SetWarnings True
    Exit Sub
ErrProc:
    Select Case err.Number
        Case 3024
            MsgBox "Tables have moved.  Please relink.", vbOKOnly
            DoCmd.OpenForm "frmReLinkJetTables"
            Resume ExitProc
        Case Else
            MsgBox err.Number & "--" & err.Description
            Resume ExitProc
    End Select
    
End Sub

Open in new window

0
 

Author Closing Comment

by:SteveL13
ID: 39794709
Nice!  Thank you.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question