Update form field

  • Thread starter Thread starter Gordon
  • Start date Start date
G

Gordon

On my form I want to have field "Updated by" that I want
to populate with the user's system network logon name. I am using a
function obtained from Dev Ashish' website:

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


I have tried (in the beforeupdate event of the form):

Me!UpdatedBy = fOSUserName

and even Me!UpdatedBy = fOSUserName()

....but it doesn't work.


Can anyone help?

Gordon
 
Me!UpdatedBy = fOSUserName should work. Is the table field Updatedby a text
data type? Are you sure of the name? If it is a textbox, I would get in the
habit of naming it "txtUpdatedBy" with the source set to the table's field
UpdatedBy.

Finally, in the immediate window, type ?fOSUserName and see if it is
returning a name.

Damon
 
Me!UpdatedBy = fOSUserName should work.  Is the table field Updatedbya text
data type? Are you sure of the name?  If it is a textbox, I would get in the
habit of naming it "txtUpdatedBy" with the source set to the table's field
UpdatedBy.

Finally, in the immediate window, type ?fOSUserName and see if it is
returning a name.

Damon














- Show quoted text -
Thanks for the confirmation Damon. I got the code to work in a
different database but not the one I was looking at. Strange.
Gordon
 
Back
Top