Link to home
Start Free TrialLog in
Avatar of ajaeclarke
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.
SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of [ fanpages ]
[ fanpages ]

:)

However, shouldn't the definition be:

Function strFull_User_Name(Optional ByVal strUserName As String = "") As String

In case the "strUserName" is to be used?

BFN,

fp.
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.
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.
Avatar of ajaeclarke

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
To be completely correct, you have to change
Function fGetFullNameOfLoggedUser() As String
to
Function fGetFullNameOfLoggedUser(Optional ByVal strUserName As String = "") As String

In that case you can use the function on 2 ways:
1) fGetFullNameOfLoggedUser
2) fGetFullNameOfLoggedUser "MyUserName"
Thanks again.

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$(fGetFullNameOfLoggedUser, Instr(fGetFullNameOfLoggedUser, ",") + 2)

Or alternatively, if "Firstname Surname"...

strFirstName = Left$(fGetFullNameOfLoggedUser, Instr(fGetFullNameOfLoggedUser, " ") - 1)

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