Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto complete name of logged in user

Status
Not open for further replies.

tizwaz

Technical User
Aug 8, 2002
437
0
0
GB
I have a form to add records and would like the field loggedby to auto complete with the name of the person currently logged in. I have a table (TblStaff which has 2 fields FullName and login). I believe you can get the logged in username with a function (something to do with Environs?) but how to I get that to look up the username in my table and complete the full name into the form field?
 
You could use dlookup in conjunction with a function to return the login name. Environ will work or you can use something like
Code:
Public function getUserName() as string
  getUserName = NZ(dlookup("FullName","tblStaff","Login = '" & fOsUserName & "'"),"Name Not Found")
end function

I wrapped it in the Null to zero so it does not through an error if name not found.
 
Thanks very much this works fine and I have my form auto complete with this when a new record is created. One more thing - I need to set the ID to the next number (for reasons (data imported with existing numbers) I have been unable to have an auto number.) I'm guessing I need some sort of dlookup max type expression but not sure how to word it. Would you be able to point me in the right direction?
 
Have a look at the DMax function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top