Link to home
Start Free TrialLog in
Avatar of urjudo
urjudoFlag for United States of America

asked on

How to pull last name only from two difference login

Hi Experts,
I have a question about how to pull only last name under two difference login.
a). Login as John.Doe
     how do I only pull Doe

b). JDoe
     how do I only pull Doe

Thanks,
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

if the format of the two login name are consistent i.e.,
a. separated by a dot
b. first and second letter are uppercase

confirm if this is correct.



this can be done using VBA codes
This function will return the characters after any specified character(s):

<><>
Function LastBit(strNa As String, optional strDelimiter As String)
'this function returns the characters to the right of the first sought character
'if no delimiter is passed in, a space will be used as the delimiter

If strDelimiter = "" Then strDelimiter = " "
'SEEKING FROM THE RIGHT END OF THE STRING

   LastBit = Right(strNa, Len([strNa]) - InStrRev([strNa], strDelimiter))
End Function
<><>

so pasting     ?LastBit("John.Doe", ".")         in the immediate window will return
Doe


If you want to return only the first character of a string, use

<><>
Public Function FirstChar(strText As String) As String
   FirstChar = Left(strText, 1)
End Function
<><>

pasting   ?FirstChar("JDoe")  into the immediate window will return
J
Avatar of urjudo

ASKER

answer for Rey Obrero.  
a). yes, first name and Last name is separated by a dot
b). sorry, they are lowercase.  (jdoe)
a. mid("John.Doe", Instr("John.Doe",".")+1)

b.  mid("jdoe",2)
Avatar of urjudo

ASKER

sorry, Rey Obrero.  I forgot to let you know that is a field name username.
if instr(login,".") then
   Lname=mid(login, Instr(login,".")+1)
else
  LName=mid(login,2)
end if
Ooop-- misread your second question.  Sorry!  Rey is correct.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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 urjudo

ASKER

is anyway I can put into a query?
Avatar of urjudo

ASKER

got it
Avatar of urjudo

ASKER

Thank you!!!