View Full Version : Using onchange event click to update another textbox on a form
mattster1010
07-07-2008, 05:11 AM
Good afternoon,
I have a combo box on a form [Qry_Status] that when the value is changed to 'completed' I want to populate the contents of a textbox [username] on the same form with the current users windows login name.
Can anybody point me in the right direction of how this may be achived?
Regards,
Mattster
CreganTur
07-07-2008, 05:27 AM
This function will get the username of whoever is currently logged onto a machine. Put it in a new module.
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
Environ$ ("Username")
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
Then you can assign the value of a variable to the return of this function to capture the username. Then you can set the value of the textbox to be the variable.
Dim strUserName As String
strUserName = fOSUserName()
HTH:thumb
mattster1010
07-07-2008, 05:43 AM
Thanks CreganTur,
Great help...
I would also like to know how to update textbox 'username' with textbox 'login'.value, if combobox Qry_Status = completed.
That would be a major help.
Cheers,
Mattster
CreganTur
07-07-2008, 06:08 AM
If I understand you right, then you want textbox 'username' to have the value of the username of current PC user if combobox value = 'completed'.
This will accomplish what you want:
If Me.Qry_Status = "completed" Then
Me.username = fOSUserName()
End If
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.