Modifying "text" entries

  • Thread starter Thread starter Sok Newbie
  • Start date Start date
S

Sok Newbie

Hello, I've currently set some check boxes to enter in
text such as "Tech" upon selection into a Control
Source "Word". With the code,

Sub Tech_AfterUpdate()

If Me.Tech = True Then
Me.Word = Me.Word & "Tech, "
End If

EndSub

This code was added for each of the check boxes. However,
I want to add the functionality that text will be taken if
the selection is deselected. Also, I want to delete the
last two characters after all the text has been entered
and replace it with a ".". So it'll get rid of ", " and
replace with a "." at the end. Any suggestions on how to
do any of these?
 
In your If statement, include an Else for the action to perform if the checkbox is False

If Me.Tech = True Then
Me.Word = Me.Word & "Tech, "
Else
Me.Word = Replace(Me.Word, "Tech, ", "")
End If

This will replace "Tech, " with an empty string, where ever the word may be found.

To get rid of the right 2 characters and replace them:

Me.Word = Left(Trim(Me.Word), Len(Trim(Me.Word)) - 1) & "."

Be aware that the final space may be removed by Access automatically if you let the
textbox Update prior to doing this. The Trim should take care of this problem. If the
space is there, it will remove it. If the space isn't there, nothing will happen. With the
space gone, you only need to remove the last character and replace it with the period.
 
Back
Top