Good afternoon. I have a form with a command buton and three textboxes. I have a function, which is supposed to get the user's logon name from the system and set the date to today. My OnClick procedure is:
Me.CCDApprovedBy = fOSUserName()
Me.CCDDate = Date
Me.CCDComments.SetFocus
My function is:
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 = ""
End If
End Function
When I click the command button, I get an error message the the textbox is to small for the amount of data, which is supposed to be 20. I did try changing lngLen to 20, but nothing changed. I hope that someone can point out the error of my ways. Thank you in advnce to anyone helping out.
Me.CCDApprovedBy = fOSUserName()
Me.CCDDate = Date
Me.CCDComments.SetFocus
My function is:
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 = ""
End If
End Function
When I click the command button, I get an error message the the textbox is to small for the amount of data, which is supposed to be 20. I did try changing lngLen to 20, but nothing changed. I hope that someone can point out the error of my ways. Thank you in advnce to anyone helping out.