TextBox afterUpdate conditional trim. Need Help.

P

pburling

I have two textboxes on a form for data entry of Television Stations,
txtName and txtCall.
Both are bound.
The difference between a name and a call sign is that usually the Name
has "-TV" at the end, and the Call sign does not. WXYZ-TV, for example,
is the Name. WXYZ is the Call sign.
So the user doesn't have to type the name in twice, I have coded in the
afterUpdate event of txtName so
txtCall takes the value of txtName. That is fine.

I can also cut off the "-TV" from the name by putting
Me.txtCall = Left([txtCall],Len([txtcall]) -3)
in the afterUpdate event of txtName.

Works fine.

Problem: Sometimes a station's name does NOT have "-TV" in the NAME!
So,
I wrote

If Me.txtName = "*-TV" then
Me.txtCall = Left([txtCall],Len([txtcall]) -3)
End If

But I am obviously doing something wrong as the wildcard isn't read as
a wildcard. Whatever is inside the quotes is taken literally. How do I
ask it to look for anything ending in "-TV"

I appreciate the help as I am a newbie to access.
Thanks
Peter
 
D

Duane Hookom

Try this:

Dim intWhereTV As Integer
intWhereTV=Instr(Me.txtName,"-TV")
If intWhere >0 then
Me.txtCall = Left([txtCall],intWhere-1)
End If
 
P

pburling

Thanks for getting back so quickly.
I have to run out to do an errand, but will try as soon as I am home.
Peter
 
P

pburling

Duane Hookom -
Of Course I couldn't go out without trying it.
And, of course, it didn't work.
And, of course, I played with it and then realised after researching
out instr that there were two
typos

intWhere needed to be intWhereTV

I am blown away.
It not only works, but I really learned.
Thank you for your help.
And at hyperspeed, no less!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top