| Be careful of the naming conventions used in this example. The routine has the same name as the API call so you may want to alias the API call. Public Function GetUserLogonName() As String ' ' This will obtain the users logged on name once from the system. The ' second time it is called it returns the static 'sName' variable ' Static sName As String Dim lBuffLen As Long Dim sBuffer As String Dim lRet As Long If Len(sName) > 0 Then GetUserLogonName = sName Exit Function Else lBuffLen = 128 sBuffer = String$(lBuffLen, vbNullChar) lRet = GetUserName(sBuffer, lBuffLen) If lRet < 0 Then ' ' Handle error from API here ' Exit Function End If sName = Left$(sBuffer, lBuffLen - 1) GetUserLogonName = sName End If End Function 'Example: MsgBox GetUserLogonName |
Get User Log-On Name |
India web developer web development India | Freelance web development ecommerce web developer | Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design