Solved

How alter onclick event of code for first time login

Posted on 2014-01-20
2
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 37

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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 …

737 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