capture the current user

  • Thread starter Thread starter alecarnero
  • Start date Start date
A

alecarnero

Is posible to capture the current NT USer when he/she click a button and
write this information in a table???


Thanks
 
Copy the code below into a module and name it GetUserName

You can use it to return the user name in Queries, Text boxes, Etc by calling it. Type the value of any expression as GetUserName() and it will return the strin

Option Compare Databas
Option Explici

' Declare for call to mpr.dll
Public Declare Function WNetGetUser Lib "mpr.dll"
Alias "WNetGetUserA" (ByVal lpName As String,
ByVal lpUserName As String, lpnLength As Long) As Lon

Const NoError = 0 'The Function call was successfu

Public Function GetUserName() As Strin

' Buffer size for the return string
Const lpnLength As Integer = 25

' Get return buffer space
Dim Status As Intege

' For getting user information
Dim lpName As Strin

' Assign the buffer size constant to GetUserName
GetUserName = Space$(lpnLength + 1

' Get the log-on name of the person using product
Status = WNetGetUser(lpName, GetUserName, lpnLength


' See whether error occurred
If Status = NoError The
' This line removes the null character. Strings in C are null
' terminated. Strings in Visual Basic are not null-terminated
' The null character must be removed from the C strings to be use
' cleanly in Visual Basic
GetUserName = Left$(GetUserName, InStr(GetUserName, Chr(0)) - 1
Els

' An error occurred
MsgBox "Unable to retrieve user name.
En
End I

End Functio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top