Using code from Dev Ashish to get userid on updated records.

G

Guest

I am currently using the code to get the network userid on any newly created
records. It works perfectly as I have a form with an UpdatedBy field with
the default value of =fOSUserName() which is the function name in Dev
Ashish's code. The module name that the function resides in is named
modGetUserID. However, I am trying to set up the form so that it captures
the network userid any time that a record is changed, not just when a new
record is created. This way I can keep track of who makes changes to
records. Should I just call this function in a different place or does the
code need to be changed? I have included Dev Ashish's code in case someone
doesn't know what I'm talking about. Thanks in advance for your help. Matt

'******************** 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
'******************** Code End **************************
 
G

Guest

Use the forms before update event, and create a hidden field that contains
the field of the username then simply say something like htis

me.usernamefield = fosusername().

This is untested so you may need to tweak it.
 

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