Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to default a field to NT User Name

Status
Not open for further replies.

mlocurci

MIS
Oct 17, 2001
210
0
0
US
Does anyone know how to default a field to the current user's NT login?
 
Where would that go? The user doesn't login into Access, just NT, does that matter?
 
I would use load event on the main menu or switchboard form...

Form Load ()
Dim lcName
lcName = ""
lcName = Environ("UserName")
msgbox(lcName)

Steve Medvid
"IT Consultant & Web Master"
 
I am actually looking to default a db field to that value, not get a pop up like that.
 
Well... once you grab the value... you can then write a simple db.Execute -> Update SQL...

Dim Thisdb As Database
Set Thisdb = CurrentDb
Thisdb.Execute "UPDATE SQL HERE ..."

or if the form you are using is bound to that database table, simply set the field to lcName.



Don't think I can offer any more...

Best way to learn is by experimenting ... Steve Medvid
"IT Consultant & Web Master"
 
Try This.

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

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = &quot;&quot;
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top