philiptdotcom
philiptdotcom

Reputation: 31

How to retrieve Windows userID in VB for 64-bit/Access 2013?

I need to get code to retrieve the Windows userID for the current session in VB (for Access 2013) on a 64-bit system.

I've tried the solution suggested at How to get logged-in user's name in Access vba?, but apparently this doesn't work on my 64-bit machine. I've also tried to figure out how to integrate the info at http://msdn.microsoft.com/en-us/library/office/gg278832.aspx, but I can't figure it out.

I am a NOVICE VB programmer, so I really need the actual code to do this. (I can [probably] figure out how & why the code does what it does after I see it, but I can't come up with it from scratch at this point.)

I'm hoping this answer will be helpful to others, too.

Thanks so much!

Aloha, -pt

Upvotes: 1

Views: 16912

Answers (2)

Gord Thompson
Gord Thompson

Reputation: 123419

This should work, too:

Dim wshNet As Object
Set wshNet = CreateObject("WScript.Network")
MsgBox "Hello, " & wshNet.UserName & "!"
Set wshNet = Nothing

Upvotes: 4

assylias
assylias

Reputation: 328598

The answer you linked to works on a 32 bit version of access. For 64 bit versions, you need to use a pointer-safe signature:

Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias
 "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long

(it might work with nSize As Long - I don't have a 64-bit access at hand)

Upvotes: 3

Related Questions