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

Removing specific text using chkBox 1

Status
Not open for further replies.

darinmc

Technical User
Feb 27, 2005
171
GB
Hi
I have a check box, that when clicked it inserts "t/s " at the beginning of a text box keeping other comments that may be in already...

When I uncheck the box, I dont want the text box to be null, I want it to remove just the specific part, "t/s "

Is this possibe? and how?

Code:
Private Sub chkTsh_Click()
If Me.chkTsh = True Then
Me.tInvNote = "t/s " & Me.tInvNote
Else
'Me.tInvNote = Null
End If
End Sub

Thx
Darin
 
Perhaps:

Code:
Private Sub chkTsh_Click()
If Me.chkTsh = True Then
Me.tInvNote = "t/s " & Me.tInvNote
Else
If Left(Me.tinvnote,4)="t/s " Then
   Me.tInvNote=Mid(Me.tInvNote,5)
End If
'Me.tInvNote = Null
End If
End Sub
 
That wont work as i have 2 check boxes
1 inserts "t/s "
the other
inserts "e/t "

these can be in any order, therefore i need it to find the specific keywords to remove

Thx
DArin
 
If you feel it is safe to do so, you can use Replace. It often a good idea to mention complications in the initial question.
 
Thx, i looked up the replace and found a simple example...
Code below works

Code:
Private Sub chkTsh_Click()
If Me.chkTsh = True Then
Me.tInvNote = "t/s " & Me.tInvNote
Else
Me.tInvNote = Replace(Me.tInvNote, "t/s ", "")
End If
End Sub


Sample code found
'Dim MyString
' A binary comparison starting at the beginning of the string.
MyString = Replace(Me.tInvNote, "t/s ", "")
Me.tInvNote = MyString
'MyString = Replace("XXpXXPXXp", "p", "Y")
' Returns "XXYXXPXXY".

'If Left(Me.tInvNote, 4) = "t/s " Then
' Me.tInvNote = Mid(Me.tInvNote, 5)
'End If
'Me.tInvNote = Null


Thx
Darin
 
A safer way:
Code:
Private Sub chkTsh_Click()
If Me!chkTsh = True Then
  If InStr(Me!tInvNote, "t/s ") = 0 Then
    Me!tInvNote = "t/s " & Me!tInvNote
  End If
Else
  Me!tInvNote = Replace(Me!tInvNote, "t/s ", "")
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top