Results 1 to 8 of 8
  1. #1
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55

    Newbie back for more; need some authentication help...

    Hi –

    I’m new to programming in Access and I have another challenge. I have this code that runs off a log in form (frmLogIn). Currently it opens an editor window (frmEmployeeData) if the right password is entered (see code snippet below - thanks to help from this forum!). Alternatively, I would like for it to open either the editor window (frmEmployeeData) or a menu form (frmMainMenu) depending upon whether the user who has logged in is designated as a super user (a “True” value in the [Super_User] field next to their employee ID [Emp_ID] in a table [tblEmployeeRoster]). Right now it checks the password in that same table (tbleEmployeeRoster), but now I would like it to open either one of the two forms, depending on whether the value for a different column (Super_User) in that same table (tblEmployeeRoster) is marked with a value of “True” or not.

    Can somebody just point me in the right direction as to the logic/ syntax for this? Again, a snippet of the code is below – where I believe this new logic would need to be inserted. As you can see, right now it only opens the editor (frmEmployeeData) after checking the password.

    Humbly submitted,
    (not worthy) newbie

    'Check the value of the password in tblEmployeeRoster to see if this
    'matches the value chosen in combo box

    If Me.txtPassword.Value = DLookup("Emp_Pass", "tblEmployeeRoster", _
    "[Emp_ID] = '" & Me.cboIdentity.Value & "'") Then


    Emp_ID = Me.cboIdentity.Value

    'Close the Log In form and open the Editor window

    DoCmd.Close acForm, "frmLogIn", acSaveNo
    DoCmd.OpenForm "frmEmployeeData"


    As noted, instead of opening the form, "frmEmployeeData" I need it to check what type of user this is and open either 1 of 2 different forms.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This is AIR CODE!!!
    Code:
    Dim SU as Boolean
    
    'Check the value of the password in tblEmployeeRoster to see if this
        'matches the value chosen in combo box
    
     If Me.txtPassword = DLookup("Emp_Pass", "tblEmployeeRoster", "[Emp_ID] = '" & Me.cboIdentity & "'") Then
          Emp_ID = Me.cboIdentity.Value
    End if
            
    SU = FALSE
    SU = DLookup("Super_User", "tblEmployeeRoster", "[Emp_ID] = '" & Me.cboIdentity & "'")
    
    'Close the Log In form and open the Editor window
     DoCmd.Close acForm, "frmLogIn"
    
    If SU Then
       DoCmd.OpenForm "frmEmployeeData"
    Else
       DoCmd.OpenForm "frmMainMenu"
    End if


    ---------------
    Just curious....
    How is the "Emp_ID" entered/selected?
    If you were to use a combo box, the password and the super user status could be columns in the combo box. You wouldn't have to use the DLookup() function. Just set the column widths of the two columns to zero. They would still be available but not visible.

  3. #3
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    The "Emp_ID" comes from the combo box on the log in form (cboIdentity). It shows the First Name, Last Name and Employee ID, but is bound on the Employee ID (Emp_ID). I included all 3 as visible in case there are 2 employees with the same name, they can distinguish on the basis of the Employee ID (has happened!). Interesting suggestion to use the combo box - maybe 4 variables, and only the first 3 are visible. You think that would be easier/ more efficient?

    I'm still having some problems. What's the best way to post code to show you? I recall something about preceeding with "/code" but I wasn't clear about that. Sorry - new to the forum, but want to follow the protocols...

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What's the best way to post code to show you? I recall something about preceeding with "/code" but I wasn't clear about that.
    Click the "Go Advanced" button. At the right of the middle tool bar is the "#". This inserts the tags for pasting on code examples.

    The "Emp_ID" comes from the combo box on the log in form (cboIdentity). It shows the First Name, Last Name and Employee ID, but is bound on the Employee ID (Emp_ID). I included all 3 as visible in case there are 2 employees with the same name, they can distinguish on the basis of the Employee ID (has happened!). Interesting suggestion to use the combo box - maybe 4 variables, and only the first 3 are visible. You think that would be easier/ more efficient?
    Yes. Why use DLookup(), when you already have the data in the control? Would you post the SQL of combo box "cboIdentity" row source?

    It would be something like:
    Code:
    SELECT Emp_ID, Emp_ID & " - " & [LastName] & ", " & [FirstName], [Emp_PW], [SuperUser] FROM tblEmployeeRoster ORDER BY [LastName], [FirstName];
    The bound column would be 1
    Column count = 4

    To get the password, you would use Me.cboIdentity.Column(2) (remember - zero based, so 3rd column is 2)
    For SuperUser, use Me.cboIdentity.Column(3)

    Note: can't use "Password" as a field name - it is a reserved word in Access.
    Here is a list of reserved words: http://allenbrowne.com/AppIssueBadWord.html

  5. #5
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Thanks, Steve - I'll take a closer look at this. I really appreciate your help!

  6. #6
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55

    Thumbs up

    Steve,

    Okay, I'm back. I used the combo box and it appears like the SQL statement "Employee ID - Last Name, First Name" (I like that better, BTW). The first (bound) column is Emp_ID, the expression is second, Emp_Pass is third and Super_User is fourth. It now works! Copy of the code is below - thanks again, Steve - you're the man!!!

    Very grateful,
    David

    Code:
        'Check the value of the password in tblEmployeeRoster to see if this
        'matches the value chosen in combo box
        If Me.txtPassword.Value = Me.cboIdentity.Column(2) Then
            Emp_ID = Me.cboIdentity.Value
            'Close the Log In form and open the Editor window
            
            If Me.cboIdentity.Column(3) = True Then
                DoCmd.OpenForm "frmMainMenu"
            Else
                DoCmd.OpenForm "frmEmployeeData"
            End If
            DoCmd.Close acForm, "frmLogIn", acSaveNo
        Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Excellent

    Question: You have
    Code:
    DoCmd.Close acForm, "frmLogIn", acSaveNo
    Why do you have "acSaveNo"?
    That argument is used if the design of the form has changed.
    You are not changing the design of the log in form. I have never used "acSaveNo" when closing a form.

    I just use
    Code:
    DoCmd.Close acForm, "frmLogIn"
    "DoCmd.Close" will work also, but I like specifying which form to close.

  8. #8
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Hi Steve -

    Sorry took so long to reply - got sidetracked on another project. To be perfectly honest, I simply "bastardized" the code from somebody else, so that's why. I totally agree with you - no reason to change the design of the form, so I'll take it out.

    I just submitted another post that concerns the same Log In form (I also posted all the code for it). It relates to verifying whether the user is active. I forgot to add that and now that I have, the super user authentication no longer works as it should (it doesn't open one form or the other depending on what the user status is = super or not - it opens the same form every time). Basically, the Log In form needs to check: password, whether the user is active or not, and their status (super or not). It will need to save their employee ID in "memory" for use by other objects (namely the Editor will need to pull up the appropriate record for the user who logged in unless it's a super user, that user should have access to all records in the editor).

    Sorry I'm muddleing through this piecemeal. For what it's worth, I'm learning quite a bit from you. Thanks again for all of your help!!!

    Regards,
    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access User Authentication
    By hi.its.anu in forum Access
    Replies: 1
    Last Post: 08-23-2012, 04:56 PM
  2. Replies: 4
    Last Post: 05-21-2012, 08:21 AM
  3. avoid sql server authentication
    By JJCHCK in forum Programming
    Replies: 0
    Last Post: 02-23-2012, 10:36 AM
  4. Email from Access 2003 with SMTP authentication
    By prstoessel in forum Programming
    Replies: 1
    Last Post: 12-16-2011, 12:07 AM
  5. Password Authentication
    By jmjbear in forum Programming
    Replies: 8
    Last Post: 11-27-2011, 02:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums