Share via

Returning the Computer Name with VBA

Anonymous
2020-10-05T12:30:50+00:00

I have created a Table to Log when users are accessing the Access Systems through out the business.

I can't find a way of returning the Computer Name

Is there a command or dlookup function in VBA that returns the name of the Computer being used?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. HansV 462.6K Reputation points
    2020-10-05T13:05:35+00:00

    You can use

    Environ("computername")

    in VBA. You can use this in your code, but you cannot use it directly in expressions in a table or query, but you can create a custom function for this purpose:

    Function ComputerName() As String

        ComputerName = Environ("computername")

    End Function

    Use like this in a query, for example:

    TheName: ComputerName()

    Was this answer helpful?

    10+ people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-10-05T23:15:32+00:00

    Do be careful using Environ values as they can easily be spoofed.

    I'd recommend using something like

    CreateObject("WScript.Network").ComputerName

    You may also like to review

    https://www.devhut.net/2020/03/17/vba-get-the-computer-name/

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2020-10-05T13:39:56+00:00

    Thanks jdraw

    Useful site which I will use going forward

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-10-05T13:28:57+00:00

    Thanks HansV

    Very useful and works a treat

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-10-05T13:02:38+00:00

    See this link for some options for getting the info.

    Was this answer helpful?

    0 comments No comments