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,
urjudoAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:
if instr([username],".") then
   Lname=mid([username], Instr([username],".")+1)
else
  LName=mid([username],2)
end if
0
 
Rey Obrero (Capricorn1)Commented:
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
0
 
Paul Cook-GilesAccess/VBA/SQL Database DeveloperCommented:
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
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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

b.  mid("jdoe",2)
0
 
urjudoAuthor Commented:
sorry, Rey Obrero.  I forgot to let you know that is a field name username.
0
 
Rey Obrero (Capricorn1)Commented:
if instr(login,".") then
   Lname=mid(login, Instr(login,".")+1)
else
  LName=mid(login,2)
end if
0
 
Paul Cook-GilesAccess/VBA/SQL Database DeveloperCommented:
Ooop-- misread your second question.  Sorry!  Rey is correct.
0
 
urjudoAuthor Commented:
is anyway I can put into a query?
0
 
urjudoAuthor Commented:
got it
0
 
urjudoAuthor Commented:
Thank you!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.