Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    May 2003
    Dudley, West Midlands, England
    Thanked 0 Times in 0 Posts

    Network usercodes (Access97)

    Can anyone tell me if the network usercode logged on to a machine using an Access97 system is available to that system? That is, can I get the usercode in VBA somehow?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Network usercodes (Access97)

    You can put the following code in a standard module. First, an API declaration that must be in the declarations section at the top of the module:

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
    (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

    The function to retrieve the network logon name:

    Public Function NetUser() As String
    Dim strName As String
    Dim strUserName As String
    Dim intPos As Integer
    strName = vbNullString
    strUserName = Space(25)
    If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
    intPos = InStr(strUserName, vbNullChar)
    NetUser = Left(strUserName, intPos - 1)
    NetUser = "-unknown-"
    End If
    End Function

    You can use this in code, and also in queries and in expressions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts