Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How alter onclick event of code for first time login

Posted on 2014-01-20
2
Medium Priority
?
436 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 40

Accepted Solution

by:
PatHartman earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

810 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