does anyone know how to return a windows login id to access?

T

ttaazzyy

Thank you George.

I tried your suggestion but I still can not get it to work.

Do i need to do something else? I copied the following into my code.

Option Compare Database

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

I copied the code into a sub as below.

'****Begin sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String

On Error GoTo BeforeUpdate_Err
strUserName = String$(20, 0)
lngLen = 100
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
UserModified = Left$(strUserName, lngLen - 1)
Else
UserModified = vbNullString
End If

' Set bound controls to system date and time.
DateModified = Date
TimeModified = Time()

BeforeUpdate_End:
Exit Sub

BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub

'****End sub
Thanks
 
P

pietlinden

Say there's a control on your form called 'txtUsername', then in the
BeforeUpdate event, you would need to add a line to your code:

Me.txtUserName=environ("Username")

If you have implemented security and are using DAO, you can use
CurrentUser()

?fOSUserName
Pieter

?environ("Username")
Pieter

?currentuser()
Admin

As you can see, the last only works if you've implemented Access
security
 
D

Douglas J. Steele

If UserModified is a control on your form (or even just a field in the
form's recordset), try using Me!UserModified.

Otherwise, explain what "can not get it to work" means. Do you get an error?
If so, what's the error?
 
D

Douglas J. Steele

I always cringe when people suggest using an environment variable for this
purpose, given how easy it is to reset an environment variable.

Far safer, in my opinion, is to use the GetUserName API call.
 
Top