access form

shrive22

Board Regular
Joined
Jun 10, 2002
Messages
120
does anyone know if theres a way to capture the username of the person logged in to windows from an access form???

thanks for the help
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I got this from xl-logic.com but it should work for Access.

Code:
Private Declare Function GetUserName Lib "advapi32.dll" _
        Alias "GetUserNameA" ( _
        ByVal lpBuffer As String, _
        ByRef nSize As Long) As Long

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

Public Property Get ComputerName() As String

  Dim stBuff As String * 255, lAPIResult As Long
  Dim lBuffLen As Long
  
  lBuffLen = 255
  
  lAPIResult = GetComputerName(stBuff, lBuffLen)
  
  If lBuffLen > 0 Then ComputerName = Left(stBuff, lBuffLen)

End Property
Public Property Get UserName() As String

  Dim stBuff As String * 255, lAPIResult As Long
  Dim lBuffLen As Long
  
  lBuffLen = 255
  
  lAPIResult = GetUserName(stBuff, lBuffLen)
  
  
  If lBuffLen > 0 Then UserName = Left(stBuff, lBuffLen - 1)
  

End Property

Then you can use UserName (and computer name, if you want it) as a variable in your initialization code.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,374
Members
451,642
Latest member
mirofa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top