Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jul 2004
    Location
    Greenville, North Carolina, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include network login id in Path (2002)

    Someone was kind enough to post a form/vb code with the necessary information to browse to a path to retrieve data from an Excel spreadsheet. Now I would like to be able to change the path to something like: c:documents and settings+network login+desktop so that the path would always reflect who is logged on. I found the following code on "The Access Web" that looks like it would help me do what I want to do, but I cannot get it to work. I am adding the path above to the field in the form, and having the form run this function when the form opens: ******************** 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 **************************

    Could anyone give me an idea of how to make this work? Also, any resources I could access/purchase that would give me a better idea of how to do this on my own.

    Thanks for the help.

    Gary O

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Include network login id in Path (2002)

    In general, it is best to place code involving Windows API functions in a standard module, the type you create by clicking New in the Modules section of the database window.

    You can use the fOSUserName function anywhere in the database, for example in the form

    "Cocuments and Settings" & fOSUserName & "Desktop"

  3. #3
    New Lounger
    Join Date
    Jul 2004
    Location
    Greenville, North Carolina, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Include network login id in Path (2002)

    Thanks, that took care of my problem. I had to enter: & fOSUserName() & to get it to work.

    Gary O

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Include network login id in Path (2002)

    Yes, the brackets () are required in expressions in queries and in the control source of controls on forms or reports. I forgot to mention that, sorry.

Posting Permissions

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