Updating number of character in textbox (1 Viewer)

JoseO

Registered User.
Local time
Today, 08:08
Joined
Jul 14, 2013
Messages
72
Hello -

May be I have been staring at code a bit too long.

I have a two textboxes.

In one, the user may enter up to 189 characters. The second textbox acts as a "character reader." As the user types in textbox1, textbox2 subtracts the characters remaining and provides the user "on the fly" characters remaining readout:

Code:
Private Sub Textbox1_Change()
Textbox2 = 189 - Len(Textbox1.Text) & " characters remaining."
End sub
This all works well. But, where I am finding trouble is when the user moves to the next record in the form. Textbox2 does not update. In other words, if record 1 has no characters in textbox1, textbox2 should read 189. If the user moves to record 2 and there are 10 characters in textbox1 then textbox2 should read 179 but it doesn't :banghead:

I can enter a simple formula in textbox2 and it works fine when I move through the records but then I lose the "on the fly" character counting.

Any help is very much appreciated. Thank you much!
 

JHB

Have been here a while
Local time
Today, 14:08
Joined
Jun 17, 2012
Messages
7,732
Put the code you've in the form's "On Current" event.
 

MarkK

bit cruncher
Local time
Today, 06:08
Joined
Mar 17, 2004
Messages
8,178
The coded solution to this problem is that both the TextBox1_Change event and the Form_Current event should call the same routine...
Code:
Private Sub Form_Current()
   ResetForm Me.Textbox1.Value
End Sub
   
Private Sub Textbox1_Change()
   ResetForm Me.Textbox1.Text
End sub

Private Sub ResetForm(Text1 As String)
   Me.Textbox2 = 189 - Len(Text1) & " characters remaining."
End Sub
...because both of those events will potentially impact the value of Textbox2.
hth
Mark
 

JoseO

Registered User.
Local time
Today, 08:08
Joined
Jul 14, 2013
Messages
72
JHB & MarkK,

Thank you so much for your feedback. I had already tried putting the code in the Form_Current event BUT after doing one more check on it, I realized that I failed to remove the ".text" portion in the event.

I simply copy and pasted from the Textbox1_Change to the Form_Current and never bothered to remove the ".text"

It all works wonderfully now. Thank you again to both of you for your willingness to help and such quick feedback; very thankful!
 

Users who are viewing this thread

Top Bottom