Results 1 to 4 of 4
  1. #1
    bakkouz is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    25

    Help with Matching Envir data with a combo selection in Access 2007 Login screen.

    Hiya,
    Newbie here.

    I am using the Login screen described in this article. and it works fine.
    since I am on a domain network, I also added 2 text boxes to display the Username and Computername. Me.txtUser = Environ("UserName") and Me.txtComp = Environ("ComputerName"). which also work fine.

    Now, what I've been trying to do is to automatically match the Environment Username with a username selection from the combo box.

    ie: if the Envir Username is e09115 I want the default value for the combo box for cboEmployee to be set to User1, and so forth.

    I've tried doing something like:

    Private Sub Form_Load()
    Me.txtUser.SetFocus
    Me.txtUser = Environ("UserName")
    Me.txtPassword.SetFocus
    End Sub

    Private Sub txtUser_LostFocus()
    If IsNull(Me!txtUser) Or Len(Me!txtUser) < 1 Then
    Me!cboEmployee = ""
    ElseIf Me!txtUser = "e09115" Then Me!cboEmployee= "User1"
    ElseIf Me!txtUser = "e05872" Then Me!cboEmployee = "User2"
    Else


    Me!cboEmployee = "Unknown User"
    End If
    End Sub

    But this did nothing.

    I'm not sure what's wrong, maybe its because cboEmployee has 2 columns and the first column is hidden? that's why it doesn't set the value? I really don't know.

    I've been tryin to make this work all morning and here I am 5 hours later, desperate.

    I just newly starting learning Access and Ive come to a dead end. Any help would be much appreciated.

    Thank you.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Is the username of your combo box also the bound column for instance you said you're trying to pass e09115 to your combo box.

    Is the column that e09115 would appear in the bound column?

    If not you will have to perform some sort of lookup for instance

    Me.comboboxname = DLookup("[PersonID]", "Tbl_People", "[PersonNetworkID] = '" & Environ("username") & "'")

    Where comboboxname would be the name of your combobox
    personid would be the unique identifier of your users
    tbl_people would be your login identifier table
    personnetworkid would be the id on your tbl_people that corresponds to their network id.

    EDIT: The key here is that you can only set the value of the combo box based on the BOUND COLUMN (as far as I know, I've never tried it another way)

  3. #3
    bakkouz is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    25
    rpeare:
    Where should I add the line:
    Me.comboboxname = DLookup("[PersonID]", "Tbl_People", "[PersonNetworkID] = '" & Environ("username") & "'")
    ?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    in the ON LOAD property of your login form I would think. If I understand your problem you want the user to be automatically filled based on who is logged into that machine. Keep in mind you must have the person's network login name in a table in your database to perform the lookup and you have to alter all the field/table names from my dlookup to match what's in your database.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-29-2014, 09:58 PM
  2. Login Screen in Access
    By Di7bash in forum Access
    Replies: 3
    Last Post: 03-18-2014, 11:57 PM
  3. Login ID Code for Access 2007 not working
    By amangupts in forum Programming
    Replies: 25
    Last Post: 07-07-2011, 01:28 PM
  4. Replies: 0
    Last Post: 06-29-2011, 01:04 PM
  5. Output Combo Box Selection to screen
    By mrcleanva in forum Access
    Replies: 3
    Last Post: 10-19-2010, 03:31 PM

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 - Senior Forums