Tom Crowfoot
asked on
Dlookup username
Dear Experts.
In Access 2010 I'm struggling with a Dlookup ...
I have a Function that gets the user's network Login (GetOSUserName()) & this happily displays the login name all correctly in a text box ("UserNameTextBox"). What I am trying to do is create another text box whose data is derived from a dlookup of that username in a table called "TBL-Users". This table contains various fields, the one i want to have returned is "FirstName"
I have got this far:
Control Source = DLookUp("FirstName","TBL-U sers","[Lo gin] = '" & [UserNameTextBox] & "")
But I just get a #Error returned
I have also tried to bypass using the [UserNameTextBox] and go straight for a lookup on the Function using
Control Source = DLookUp("FirstName","TBL-U sers","[Lo gin] = '" & GetOSUserName() & "")
But I just get a #Error returned
Can anybody help
In Access 2010 I'm struggling with a Dlookup ...
I have a Function that gets the user's network Login (GetOSUserName()) & this happily displays the login name all correctly in a text box ("UserNameTextBox"). What I am trying to do is create another text box whose data is derived from a dlookup of that username in a table called "TBL-Users". This table contains various fields, the one i want to have returned is "FirstName"
I have got this far:
Control Source = DLookUp("FirstName","TBL-U
But I just get a #Error returned
I have also tried to bypass using the [UserNameTextBox] and go straight for a lookup on the Function using
Control Source = DLookUp("FirstName","TBL-U
But I just get a #Error returned
Can anybody help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic - thank you very much
check this out, you where missing the closing quote.
also, you need to make your code fail-safe against sql injection:
Control Source = DLookUp("FirstName","TBL-U sers","[Lo gin] = '" & replace([UserNameTextBox], "'", "''") & "' ")
also, you need to make your code fail-safe against sql injection:
Control Source = DLookUp("FirstName","TBL-U
<<This table contains various fields, the one i want to have returned is "FirstName">>
Just a word of caution; if your trying to fetch more then one or two fields from that user record, you'd be better off to open a recordset in code and only fetch the record once and have all the fields available then you will be to make repeated DLookup() calls.
Jim.
Just a word of caution; if your trying to fetch more then one or two fields from that user record, you'd be better off to open a recordset in code and only fetch the record once and have all the fields available then you will be to make repeated DLookup() calls.
Jim.
= DLookUp("FirstName","[TBL-
(and avoid spaces and special characters in your naming conventions)