As a Newbie I've picked up a heap of tips and tricks from this NG but I
have been battling to get the current user's Netwok Login ID recorded
on a form at the time a new record is created or modified. I haven't
implemented Access security, and want their Network Login ID. The
network is running W2K server and all users have unique login ID's.
I run A2K and I've found Dev Ashish's code at
http://www.mvps.org/access/api/api0008.htm . I tried two approaches
using this code:-
First was to make the module and then I created a field on the table
called FosUsername and a control on the form called FOSUserName.
Nothing happened so I guess that I missed something else.
Second, I read elswhere in the NG that I should paste all the code
into the "Before Update" event for the control. This I did, but when I
came to save the form, it gave me the error:-
The expression On Current you entered as the event property setting
produced the following error:- Only comments may appear after End Sub,
End Function ........
After pasting the code in it looked like this :-
Private Sub fosusername_BeforeUpdate(Cancel As Integer)
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
End Function
Could someone be kind enough to assist - bearing in mind that writing
code is not something I've studied.
Chantelle