Full Version: windows user in a textbox
UtterAccess Forums > Microsoft® Access > Access Forms
Artimus20
trying to get a texbox in my form to display the name of the person logged in to windows. i use a SIGNATURE in my emails that accomplishes this when sending reports, but i can't get it to work in my forms textbox??
This is what i use for email:
-----------------------------------------------------------------------------------
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
------------------------------------------------------------------------------------
SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\General.htm"
If Dir(SigString) <> "" Then
SIGNATURE = GetBoiler(SigString)
Else
SIGNATURE = ""
End If
-------------------------------------------------------------------------------------
theDBguy
A better approach is to use the API method shown here. Then you can use this a control source for your textbox:
fOSUserName()
Hope that helps...
Artimus20
hmm, getting a compile error. this is exactly how what i pasted:
--------------------------------------------------------------------------------------------------
Public Function fOSUserName() As String
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
' 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 = vbNullString
End If
End Function
--------------------------------------------------------------------------------------------------
Artimus20
got it to work,
hanx its perfect.
theDBguy
What was the err... well, never mind. Glad you got it fixed. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.