Code for using a variable generated on loading a form to lookup a table and based on

accessaspire219

Registered User.
Local time
Today, 16:24
Joined
Jan 16, 2009
Messages
126
I have a form which when opened reads the username of the person that is logged on to the computer.
The user is stored as a variable. This variable is called strUser
I have a table in the database which contains the windows username and key among other fields. I want to write a code which will look for the key for a value of strUser and based on the key populate two text boxes bname and sname.
For example, there is a user abc, when he opens the form strUser=abc
Now the form should take this value (abc) and look up table A [Key] field.
If the Key = B – set bname=strUser
If key=S –set sname=strUser
If key=m –set sname=blank and bname=blank
As you can see, I have the logic in my head, but VBA is not my forte. Can anyone guide me with this?
 
I would use Dlookup function get the key from your table.

Then use a CASE statement to populate the two text boxes depending on the value of the key.
 

Users who are viewing this thread

Back
Top Bottom