G
Guest
I have 5 text boxes on my form, each with the max length set to 255
characters. On the AfterUpdate and KeyUp events for each text box I will call
the one procedure to show the max number of characters left to be entered.
Instead of having 5 different procedures I have tried to make one which takes
in the textbox name and label name, in this case txtNotes and lblNotes.
However, i'm having loads of problems with this code and it doesn't even come
close to working. Can any one see what's wrong with it?
Private Sub txtNotes_AfterUpdate()
TextBoxLengths "txtNotes", "lblNotes"
End Sub
Private Sub txtNotes_KeyUp(KeyCode As Integer, Shift As Integer)
TextBoxLengths "txtNotes", "lblNotes"
End Sub
Public Sub TextBoxLengths(cntTextBoxName, cntLabelName As Controls)
If Me.ActiveControl.Name = cntTextBoxName Then
Me.Controls(cntLabelName.Caption) = "(" & 255 -
Len(Me.Controls(cntTextBoxName.Text)) & ")"
If Len(Me.Controls(cntTextBoxName.Text)) < 1 Then
Me.Controls(cntLabelName.Visible) = False
Else
Me.Controls(cntLabelName.Visible) = True
End If
Else
If Len(Me.Controls(cntTextBoxName)) > 0 Then
Me.Controls(cntLabelName.Visible) = True
Me.Controls(cntLabelName.Caption) = "(" & 255 -
Len(Me.Controls(cntTextBoxName)) & ")"
Else
Me.Controls(cntLabelName.Visible) = False
End If
End If
End Sub
Thanks!
characters. On the AfterUpdate and KeyUp events for each text box I will call
the one procedure to show the max number of characters left to be entered.
Instead of having 5 different procedures I have tried to make one which takes
in the textbox name and label name, in this case txtNotes and lblNotes.
However, i'm having loads of problems with this code and it doesn't even come
close to working. Can any one see what's wrong with it?
Private Sub txtNotes_AfterUpdate()
TextBoxLengths "txtNotes", "lblNotes"
End Sub
Private Sub txtNotes_KeyUp(KeyCode As Integer, Shift As Integer)
TextBoxLengths "txtNotes", "lblNotes"
End Sub
Public Sub TextBoxLengths(cntTextBoxName, cntLabelName As Controls)
If Me.ActiveControl.Name = cntTextBoxName Then
Me.Controls(cntLabelName.Caption) = "(" & 255 -
Len(Me.Controls(cntTextBoxName.Text)) & ")"
If Len(Me.Controls(cntTextBoxName.Text)) < 1 Then
Me.Controls(cntLabelName.Visible) = False
Else
Me.Controls(cntLabelName.Visible) = True
End If
Else
If Len(Me.Controls(cntTextBoxName)) > 0 Then
Me.Controls(cntLabelName.Visible) = True
Me.Controls(cntLabelName.Caption) = "(" & 255 -
Len(Me.Controls(cntTextBoxName)) & ")"
Else
Me.Controls(cntLabelName.Visible) = False
End If
End If
End Sub
Thanks!