Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2014

    Unanswered: VBA username/password code help

    Good Morning,

    First time user and poster. Thank you for the acceptance into the community.

    I am not very proficient with Access but I will try to use as many of my resources as possible before asking for assistance. At this point I just have no clue as to how to accomplish what I would like and have run into a brick wall when searching with google for examples.

    I have a table that contains the following fields:
    WorkerName, WorkerPassword

    I then have a form that requires a user to put in their username/password for their name to be entered into the specific field automatically. The code I pasted below does a great job and works. Unfortunately, I have a total of 4 fields that require the same type of username/password entry verification and the same person may sign off more than one field. In order to address this, I have made a seperate table/username for each field. I know there is a more efficient way to accomplish this, I just do not know how.

    What I would like to have is one table with the following fields.

    PrimaryID(AutoNumber), WorkerName(txt), WorkerPassword(txt), Technician (txt), QualityControl(txt), Supervisor(txt), MaintenanceSupervisor(txt). The last four fields would be a yes or a no stating if the person is authorized to make that entry. If the field value is yes, the rest of my code would run. If the entry in the field is No, then a MsgBox would popup saying that they are not authorized to sign the appropriate entry.

    Any help would be appreciated. I know I would have to change the coding slightly for each field that requires validation. Which are:

    Field one = Technician
    Field two = Quality Control
    Field three = Supervisor
    Field four = MaintanceSupervisor

    -------------Working Code Thus Far----------------

    Private Sub CmdPassword_Click()

    Dim strUserName As String
    Dim strPassword As String
    Dim strUserNamePassword As String

    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.TxtUserName) Or Me.TxtUserName = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.TxtPassword) Or Me.TxtPassword = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Exit Sub
    End If

    'Combine User Name and Password entered into Login Form

    strUserNamePassword = TxtUserName & TxtPassword

    'Search for User Name and Password entered from the Login Form in the Tbl_Representatives

    strUserName = Nz(DLookup("WorkerName", "Tbl_Corrected_by_maf", "WorkerName= '" & Me.TxtUserName & "'"), "")
    strPassword = Nz(DLookup("WorkerPassword", "Tbl_Corrected_by_Maf", "WorkerPassword= '" & Me.TxtPassword & "'"), "")

    'Validate the User Name and Password

    If strUserNamePassword = (strUserName & strPassword) Then
    Forms![Frm_VidsMaf]![ComboBoxCorrectedBy].Locked = False
    Forms![Frm_VidsMaf]![ComboBoxCorrectedBy].Value = TxtUserName
    Forms![Frm_VidsMaf]![ComboBoxCorrectedBy].Locked = True
    DoCmd.Close acForm, "Frm_Corrected_Login", acSaveNo
    MsgBox "Authorization Validated, Entry Entered."

    'If the username/password is incorrect
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"

    End If

    End Sub

    Thank you,

  2. #2
    Join Date
    Apr 2014
    Provided Answers: 35
    If the user has 4 settings in the table
    Tech (y/n)
    Qual (y/n)
    Super (y/n)
    Maint (y/n)

    I think the app would load the userID (this is where a User class, or a collection would come in but maybe beyond the scope right now.)

    so load userID and their settings, THEN when the form loads assign the locks

    cboMaint.locked = user.Maint = N
    cboSuper.locked = user.Super = N
    Last edited by ranman256; 09-02-14 at 13:04.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts