Make sure the code goes in a *general* code module, not a module attached to
an Access object (i.e., a form or report) or attached to another class. That
(and declaring it Public) is what allows it to be called from "anywhere,
anytime".
In the VB editor: Insert>Module
--
HTH,
George
I'm assuming the code you are referring to uses the GetUserName WinAPI
call.
Place the code you found in a module, make sure the function is
public. Now you can refer to that function from lots of places. I
have a function like this that I call NTUserLogin. It is in a module
and looks like this:
Public Declare Function GetUserName _
Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As
String, _
nSize As Long) As
Long
Public Function NTUserLogin() As String
Dim strBuffer As String
Dim lngSize As Long
strBuffer = Space(255)
lngSize = Len(strBuffer)
Call GetUserName(strBuffer, lngSize)
If lngSize > 0 Then
NTUserLogin = UCase(Left(strBuffer, lngSize - 1))
End If
End Function
If I wanted to log the user when a record is saved, I would add a
bound textbox to the form and then set it equal to NTUserLogin in the
before update of the form:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Text1 = NTUserLogin
End Sub
Sounds to me