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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove all text after the first space in a text box 1

Status
Not open for further replies.

Vec

IS-IT--Management
Joined
Jan 29, 2002
Messages
418
Location
US
I have a text box named txtDate

I need the "lost focus" event of the box to do the following:
Sometimes there may be characters after the date, however there is always a space first for example:
02/03/02 A332
I need the lost focus of the text box to basically remove everything after the space so that just the clean date is left. The characters after the space (if any) will be of varying charcter counts. -
radium.gif

Looking Toward The Future
 
Dim lngInstr as Long

lngInstr = Instr(1,text1.Text," ")
if lngInstr > 0 then
text1.Text = Left$(tetx1.text,lngInstr)
End if Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Hi

JohnYingling's code does exactly what you asked for: remove everything
*after* the space, however this leaves the space at the end of your string.

If you want to take that out as well, then modify the code as such:

text1.Text = Left$(tetx1.text,lngInstr - 1)

HTH
Rowland
 
Thank you to both of you! I was just about to ask that question Rowland! Thanks. And thanks as well John.

-
radium.gif

Looking Toward The Future
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top