Tracking Users via Network Login

  • Thread starter Tiffany P. via AccessMonster.com
  • Start date
T

Tiffany P. via AccessMonster.com

I placed the following code in my module named FOSUserName. But what do I
need to do to get the user name to show on my form after update and save it
with the
record??
******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
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 = vbNullString
End If
End Function
'********************
 
A

Albert D.Kallal

You don't mention if you just want to save the last person who edited the
record (and at what time + date), or you want to save who created the
record?

For creating the record, put the following code in the on-insert event

me!TimeOfCreate = now()
me!Operator = fOSUserName()

If you want to save the last edit time, and last "operator" who changed the
record, then put your code in the forms before update event....

me!LastEditTime = now()
me!LastOperator = fOSUserName()

The above examples of course assume you created the appropriate fields in
the table for the data to be saved (eg, the above assume LastEditTime is a
date/time fields, and the field "lastoperator" is a text field...

You also need to put that api code fOSUserName() into a standard ms-access
module. Remember, make sure the module name does not conflict with any name
of a code, or sub inside of the module. So, a good module name for that code
would be "MyApiCode"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top