Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Machine name (Access XP)

    Is there a way of getting the name of the PC.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Machine name (Access XP)

    Machine name is one of the values returned in the UserRoster. See this knowledgebase article.
    Charlotte

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Machine name (Access XP)

    Thanks Charlotte, it does return the name alright. However, I have to reference a database that is not the same as the one I am currently in.
    Is there an API that could also return it?
    Can this be done from DAO instead of ADO?

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

    Re: Machine name (Access XP)

    Access only keeps track of the machine name of the PC the user is on, not of the PC the database is on.
    DAO doesn't expose the machine name.
    What exactly are you trying to accomplish?

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Machine name (Access XP)

    I need to obtain the name of the PC that the user is on.
    They will have a database on their PC that needs to upload data to a network database.

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

    Re: Machine name (Access XP)

    Copy the following declarations to the top of a standard module (the type you create by clicking New in the Modules section of the database window, or selecting Insert | Module in the Visual Basic Editor):

    Private Const MAX_COMPUTERNAME_LENGTH As Long = 31

    Private Declare Function GetComputerNameA Lib "kernel32" _
    (ByVal lpBuffer As String, nSize As Long) As Long

    Copy the following function into the same module:

    Public Function GetComputerName() As String
    Dim dwLen As Long
    Dim strString As String
    ' Create a buffer
    dwLen = MAX_COMPUTERNAME_LENGTH + 1
    strString = String(dwLen, 0)
    ' Get the computer name
    GetComputerNameA strString, dwLen
    ' Get only the actual data
    strString = Left(strString, dwLen)
    ' Return the computer name
    GetComputerName = strString
    End Function

    You can use the GetComputerName function in VBA code and in expressions in queries etc.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Machine name (Access XP)

    Well done Hans, it works a treat.
    Thank you.

Posting Permissions

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