Want to earn $25 for telling us how you feel about the current Microsoft Learn Q&A thread experience? Help our research team understand how to make Q&A great for you.
How can I get 'computer name' using Access 2007 VBA?
Need to flag each record written to a table with the date/time Posted and a field, PostedBy, which will contain the computer name as the user will not be logging on to a network ID. But I can't find how to retrieve the computer name from the system. Does
anyone know how I would do that?
The simplest way, although not 100% dependable, is Environ("computername")
More complicated, but also more dependable:
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Function ComputerName() As String
Dim stBuff As String * 255
Dim lAPIResult As Long
Dim lBuffLen As Long
lBuffLen = 255
lAPIResult = GetComputerName(stBuff, lBuffLen)
If lBuffLen > 0 Then
ComputerName = Left(stBuff, lBuffLen)
End If
End Function
You can then use the ComputerName function.
--- Best wishes, HansV https://www.eileenslounge.com
8 people found this reply helpful
·
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.