Environ("username")

halem2

Registered User.
Local time
Today, 14:47
Joined
Nov 8, 2006
Messages
180
Hi:

Using Access 2000.

I have a login form in which I'm automaticall selecting the windows user name by using Environ("username")...thanks to KeithG. My question is: how can I pass the value of that function to another form that populates a table?

In other words, the user gets the login form with the name preselected based on whomever is logged under Windows. When user logs in it opens a form to select his own name, the course he/she just took, the course name and trainer name. All these are combo boxes.

I need to populate the user name combo box with the value preselected in the login form.

thanks for any help.
 
Use the open event of the form and the below code

Me.[ComboBoxName]=environ("username")
 
getting an error. cant assign value to this object.


:confused:
 
The "Value" of the combo box is probably NOT the username, but the userid. So, you can't assign the value of the username to it and would have to use DLookup, or something, to find the userID based on the username and set the combo value to it.
 
actually I created a query and added the UserName field to eliminate the UserID and got the same error
 
yes it is. I'm looking into the Dlookup as BobLarson suggected. Any ideas?
 
DlookUp("UserID","[TableName]","UserName='" & environ("username") & "'")

try that
 
DlookUp("UserID","[TableName]","UserName='" & environ("username") & "'")

try that
Keith:
I don't know that that one would work as I believe the square brackets need to go around the field names, not the table name.
Code:
DlookUp("[UserID]","TableName","[UserName]='" & environ("username") & "'")
 
I guess you both read faster than me! (bad joke. I know u know it)

I'm getting errors in both. (expected :=) and ")" )I'm going tokeep reading about dlookup and if I can't figure it out, I'll ask for help.

thanks to both of you. :D
 
Keith:
I don't know that that one would work as I believe the square brackets need to go around the field names, not the table name.

Bob you are correct. My intention with the brackets was to make it look like a variable because I did't know the name of the table.
 
this is straight from the horses mouth (http://support.microsoft.com/kb/208786)
which is the same as the one that KeithG did and still fails...

=DLookup("[ContactName]", "[Customers]", _
"[CustomerID]='" & Forms![Orders]![CustomerID] & "'")
 
I'm getting

Expected: List separator or )
 
You are putting this expression in the On Open event of your form, correct?
 
DlookUp("[UserID]","User","UserName='" & environ("username") & "'"

field is [UserID]

table is "User"

field on from is "UserName"
 
Add a ) to the end of your first line
Code:
DlookUp("[UserID]","User","UserName='" & environ("username") & "'"[B][COLOR="Red"])[/COLOR][/B]

Plus you will have to set a variable = DLookup(...

and then use that.
 
I did...now it errors out saying

Expected: =
 

Users who are viewing this thread

Back
Top Bottom