Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if Last Input Value of Textbox = "S" 1

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
Greetings!

I need to determine if the value of a userform textbox is equal to the letter "S".

The reasoning is in referance to showing possesion in regards to the textbox entry. In other words, the textbox is used for the last name of a person. Within the letter, I need to refer something to that person using their last name.

If their last name is Smith, that is easy...I can simply use ('s) to show possesion, which would equal Smith's. However, if their last name is Jones I would need the code to be able to determine that an "s" is the last character of the field entry and therefore only add (') to the end which would equal Jones'.

Any suggestions would be greatly appreciated!

Thanks!
 
Look up the normal string manipulation functions. In this case, I would assume the use of Right. Here is a simple example, taking a string from an inputbox - but of course it could take a string from anywhere, including your textbox:
Code:
Sub last_S()
Dim strIn As String
strIn = InputBox("Type a word.")
If Right(strIn, 1) = "s" Then
   strIn = strIn & "'"
Else
   strIn = strIn & "'s"
End If
MsgBox strIn
End Sub
Type "Smith" into the inputbox, the result is "Smith's"; type "Jones" and the result is "Jones'".

This is basic string manipulation.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top