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

bakkouz

Registered User.
Local time
Tomorrow, 01:22
Joined
Jan 16, 2011
Messages
48
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.
 
Hi..

The second column contains data, try this way..:


.....
.........
ElseIf Me!txtUser = "e09115" Then Me!cboEmployee.text= "User1"
ElseIf Me!txtUser = "e05872" Then Me!cboEmployee.text = "User2"
.....
............
 
Taruz:
Thank you, it worked! But now I'm getting the error: "can't move the focus to the control txtPassword"
So i deleted the line : Me.txtPassword.SetFocus
but now the focus is on the txtUser field, and I need it to be on the txtPassword field.
I've tried re-instating it at several places, but didn't work.
I need for the focus to be on the txtPassword field.
how do I do that?

Thanks.
 
Are all the codes will attempt to take the load event..

Code:
Private Sub Form_Load()
Me.txtUser.SetFocus
Me.txtUser = Environ("UserName")

If IsNull(Me!txtUser) Or Len(Me!txtUser) < 1 Then
Me!cboEmployee = ""
Else

 select case Me!txtUser
  case "e09115"
   Me!cboEmployee.SetFocus
   Me!cboEmployee.Text = "User1"
  case "e05872"
   Me!cboEmployee.SetFocus
   Me!cboEmployee.Text = "User2"
  case else
   Me!cboEmployee = "Unknown User"
end select

Me.txtPassword.SetFocus
End If

End Sub
 
No wait ! I'm so sorry, I spoke too fast.
It did not work :(
now the cboEmployee is blank :\
 
OK OK So very sorry, I was mistaken. it works just fine heh
sorry for being annoying :)
 

Users who are viewing this thread

Back
Top Bottom