Generally speaking I don't advise logging users into a database. As soon as you start down that road you become responsible for ensuring the bona fides of the user and that usually means storing passwords or hashes. Unless you're a genius that leaves you in the uncomfortable position of being responsible for security breaches rather than leaving such things to the O/S where a great deal more time and effort has been put into ensuring security and the passwords are stored outside of your database in the Active Directory.
This concept comes up a lot and I can say, without fear of contradiction, that all the other Access MVPs agree that to try to do it within Access is simple (and easily avoidable) folly.
Please don't see this as an attack on you personally. I would thank you for contributing your advice. I feel I would be remiss though, if I didn't warn you, and others that see that advice, that it is beyond unwise & actually quite dangerous.
As it's come up I suppose I should share how to use the easier / more reliable / certainly safer approach -
Function to Return UserName (NT Login) of Current User. If you want to store that in a TempVar then feel free. Personally I'd store it in a Static variable within a Function Procedure which would only try to determine the value when it isn't already set. Something like :
- Public Function GetOSUser()
-
Static strOSUser As String
-
-
If strOSUser = "" Then
-
'Code to get value from O/S and store in strOSUser.
-
End If
-
GetOSUser = strOSUser
-
End Function