ajaeclarke
asked on
Getting Full User Name
Hi
I have been trying to figure this one out for a while.
I would like to get the full user name to put in a welcome message when my database opens. I have found some code that gets the windows logon user name i.e. JSmith but I would like to be able to get the full name i.e. John Smith. Am at a lost as to how to achieve this.
Any help would be appreciated.
I have been trying to figure this one out for a while.
I would like to get the full user name to put in a welcome message when my database opens. I have found some code that gets the windows logon user name i.e. JSmith but I would like to be able to get the full name i.e. John Smith. Am at a lost as to how to achieve this.
Any help would be appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That's correct. If forgotten to set it back because I tested it from that function (without parameter). My mistake.
Thx fanpages to correct it.
Thx fanpages to correct it.
No problem :)
As an aside, do you know if we can change the API calls to support all versions of (32-bit) Windows?
BFN,
fp.
As an aside, do you know if we can change the API calls to support all versions of (32-bit) Windows?
BFN,
fp.
ASKER
Thanks for your prompt replies!!
Dhaest I tried your code and it works fine, so what are the changes that fp has pointed out and do I have to change anything as it is working.
Cheers
Dhaest I tried your code and it works fine, so what are the changes that fp has pointed out and do I have to change anything as it is working.
Cheers
To be completely correct, you have to change
Function fGetFullNameOfLoggedUser() As String
to
Function fGetFullNameOfLoggedUser(O ptional ByVal strUserName As String = "") As String
In that case you can use the function on 2 ways:
1) fGetFullNameOfLoggedUser
2) fGetFullNameOfLoggedUser "MyUserName"
Function fGetFullNameOfLoggedUser()
to
Function fGetFullNameOfLoggedUser(O
In that case you can use the function on 2 ways:
1) fGetFullNameOfLoggedUser
2) fGetFullNameOfLoggedUser "MyUserName"
ASKER
Thanks again.
One more quick one....if I wanted to get just the first name....how is this done?
One more quick one....if I wanted to get just the first name....how is this done?
Hi,
Are your "full names" defined as "Surname, Firstname" or "Firstname Surname"?
If "Surname, Firstname", then you will need to use the Instr() function to find the position of the comma, then use Mid$() accordingly, this:
strFirstName = Mid$(fGetFullNameOfLoggedU ser, Instr(fGetFullNameOfLogged User, ",") + 2)
Or alternatively, if "Firstname Surname"...
strFirstName = Left$(fGetFullNameOfLogged User, Instr(fGetFullNameOfLogged User, " ") - 1)
BFN,
fp.
Are your "full names" defined as "Surname, Firstname" or "Firstname Surname"?
If "Surname, Firstname", then you will need to use the Instr() function to find the position of the comma, then use Mid$() accordingly, this:
strFirstName = Mid$(fGetFullNameOfLoggedU
Or alternatively, if "Firstname Surname"...
strFirstName = Left$(fGetFullNameOfLogged
BFN,
fp.
You'll have to split the result then.
Simple example:
Private Sub Command1_Click()
Dim strName As String
Dim splitName() As String
strName = fGetFullNameOfLoggedUser
splitName = split(strName, " ")
MsgBox splitName(0) & " " & splitName(1)
End Sub
Simple example:
Private Sub Command1_Click()
Dim strName As String
Dim splitName() As String
strName = fGetFullNameOfLoggedUser
splitName = split(strName, " ")
MsgBox splitName(0) & " " & splitName(1)
End Sub
However, shouldn't the definition be:
Function strFull_User_Name(Optional
In case the "strUserName" is to be used?
BFN,
fp.