Capture 3 characters from Surname

aman

Registered User.
Local time
Today, 15:01
Joined
Oct 16, 2008
Messages
1,251
Hi guys

Can anyone please help me to capture 3 characters from the surname using vba?

e.g I am using environ("username") to capture name of the person who is logged on so how can we capture 3 letters from the surname and display in the textbox.

Thanks a lot.
 
You didn't say which 3, but you could use the Left(), Right() or Mid() functions on the result of the Environ() function.
 
Hi pbadly

I want first 3 characters of the surname so how it can be done using vba.

Thanks
 
Try something like this in the VBA screen and display the immediate window.

Sub username()
Debug.Print Mid(Environ("Username"), 8, 3)

End Sub
 
Trevor J, If the firstname is 10 characters long then it won't give the right result because final text will start from 8th character always and then will give next 3 letters.

Thanks
 
Name and last name, separated by a space assuming, is in this way.:

Code:
Dim trz As String
trz = Environ("Username")
MsgBox Left(Mid(trz, _
       InStr(1, trz, " ") + 1), 3)
 
Thanks a lot Taruz. It worked perfectly fine.:)
 

Users who are viewing this thread

Back
Top Bottom