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

Problem with a textcounter 1

Status
Not open for further replies.

olekr

Instructor
May 27, 2001
19
0
0
NO
I want to have a label or a unbound textbox which shows the number of characters written in another unbound text box (in the same form). The clue is to show how many char. left for SMS message. Someone who can help? Thanks!
Ole
 
you`ll want to use the function len() which will calculate the number of characters in a string.

Assuming you want this to be done after the user enters data within TextBox1 then just put the follow line in the AfterUpdate Event of Textbox1:

------------------------
Textbox2 = len(Textbox1)
------------------------

This will return and set the value of Textbox2 to the number of Chars in the string.

Hope this is what you wanted

Ian
 
Hi Ole!

Create the label and set it's visible property to false and then add this code to your unbound text box:

Private Sub YourTextBox_GetFocus()

YourLabel.Visible = True
If Nz(Len(YourTextBox), 0) = 0 Then
YourLabel.Caption = Format(0)
Else
YourLabel.Caption = Format(Len(YourTextBox))
End If

End Sub

Private Sub YourTextBox_Change()

If Nz(Len(YourTextBox), 0) = 0 Then
YourLabel.Caption = Format(0)
Else
YourLabel.Caption = Format(Len(YourTextBox))
If Len(YourTextBox) = YourMax + 1 Then
Call MsgBox("The maximum number of characters allowed in this field is YourMax. Please make appropriate changes to fit the field length. If you continue, Access will truncate your entry at YourMax!")
End If
End If

End Sub

Private Sub YourTextBox_LostFocus()

YourLabel.Visible = False

End Sub

Obviously, there are a variety of ways to do the error handling. What I did above, I feel, gives the user the maximum leeway. If you don't what to give them the maximum leeway, you will need to make changes. This should give you a start.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks folks!
Used the code from Jeff and now its all ok. I spend an hour referencing to me.txtBox1 instead of me.txtBox1.Text. Stupid me...Ole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top