Solved

How alter onclick event of code for first time login

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bind Combobox 4 28
Adding a new record to a SQL Server backend table from Access Form 2 27
Run Time Error 3071 26 34
Format a Field AFTER UPDATE 5 18
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

937 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

10 Experts available now in Live!

Get 1:1 Help Now