PDA

View Full Version : Is it possible to show a current user on a form using ms access 2007 database?



wedd
09-29-2010, 09:35 AM
Hi, I would like to create that when a user is logged onto the database their name and if possible the pc appears, so when they save their work on the database...it will appear to the next user who last used the database...can this be done? If so, how can this be done?



Thank you! :friends:

hansup
09-29-2010, 11:17 AM
Hi, I would like to create that when a user is logged onto the database their name and if possible the pc appears, Look at Get Login name: http://www.mvps.org/access/api/api0008.htm
Using that module you can retrieve the user name with the fOSUserName() function.

And Get computer name: http://www.mvps.org/access/api/api0009.htm
The fOSMachineName() function returns the computer name.

Imdabaum
09-30-2010, 09:00 AM
I'm not sure if this is too easy, but mvidas wrote a KB article on how to show all the Environ variables in Excel. These are more for you to reference what you might possibly use, but a lot of user information is already accessible with the Environ variables rather than reinventing the wheel.

http://www.vbaexpress.com/kb/getarticle.php?kb_id=217

It's as simple as calling them.
Environ("username")
Environ("Computername")

hansup
09-30-2010, 09:09 AM
Environ("username") may be adequate. However, environment variables can be fudged by the user. For a more secure approach the standard recommendation is to retrieve the Windows account name with the API function.

Imdabaum
09-30-2010, 09:11 AM
What do you mean they can be fudged?

hansup
09-30-2010, 09:14 AM
A user can open a command shell, change values for environment variables, then launch Access from that modified environment. It's easy! Try it.

Imdabaum
09-30-2010, 09:20 AM
Four Access related words for that....

SELECT explative FROM Vocabulary:banghead:

:motz2: Guess I'm still a beginner...

Thanks for the headsup.:thumb

hansup
09-30-2010, 09:22 AM
Love your geek humor! Back at ya ...

GRANT USER Imdabaum SLACK PRIVILEGES;

wedd
10-06-2010, 05:18 AM
Hansup, have you any an examples of the code?

davmec93
10-06-2010, 06:37 AM
You can use this function in a module
Function fOSUserName() As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

Then in the control source of the text box use =fOSUserName()

wedd
10-19-2010, 07:47 AM
thanks!