Hello:
Okay, I'm trying to pull the user login and found some code which I thought would do it, but ain't.
My code is (declared in a module):
Code:
Option Compare Database
Private Declare Function api_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function api_GetComputerName Lib "Kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function CNames(UserOrComputer As Byte) As String
'UserorComputer; 1=User, anything else = computer
Dim NBuffer As String
Dim Buffsize As Long
Dim wOK As Long
Buffsize = 256
NBuffer = Space$(Buffsize)
If UserOrComputer = 1 Then
wOK = api_GetUserName(NBuffer, Buffsize)
CNames = Trim$(NBuffer)
Else
wOK = api_GetComputerName(NBuffer, Buffsize)
CNames = Trim$(NBuffer)
End If
End Function
I then am testing in a simple form with:
Code:
Private Sub Form_Open(Cancel As Integer)
If GetUserNameA = "" Then GetUserNameA = "'Houston, we have a problem'"
If GetComputerNameA = "" Then GetComputerNameA = "VOID"
MsgBox "Your user name is " & GetUserNameA & " and your computer names is " & GetComputerNameA & "."
End Sub
However, I'm getting the houston we have a problem and void instead of the computer name and user name. Any thoughts?
Thanks in advance.
Arholly