Solved

How alter onclick event of code for first time login

Posted on 2014-01-20
2
426 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 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
Nice!  Thank you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now