Count Textbox Characters

G

Guest

Is there any way I can count the charaters in a memo field including spaces.
I currently use the following procedure.

On Error GoTo Err_Form_BeforeUpdate
If Len(Me![Notes]) > 1560 Then
MsgBox "Your notes must be less than 1,560 characters.", vbInformation,
"Exceeded Field Limit"
Cancel = True
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

I want the user to have the ability to check the count before trying to save
the record.
 
B

Brendan Reynolds

Just copy your existing If ... End If code (minus the 'Cancel = True' line)
to the Click event procedure of a command button.
 
G

Graham R Seach

What you've done is OK, but I'd be inclined to use the Change() event, so
the users know exactly when they have exceeded the limit. After all, your
users are going to be real amused when you finally tell them that you're
going to discard the last 500 (excess) characters they've just entered.
Better to let them know early, in my opinion.

Private Sub Notes_Change()
If Len(Me.Notes.Text) > 1560 Then
DoCmd.Beep
'You can also put the MsgBox here if you must
Me.Notes.Text = Left(Me.Notes, 1560)
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
G

Guest

You know what your absolutely right it happened to me already Thanx fellows I
really apprecite the help.

Graham R Seach said:
What you've done is OK, but I'd be inclined to use the Change() event, so
the users know exactly when they have exceeded the limit. After all, your
users are going to be real amused when you finally tell them that you're
going to discard the last 500 (excess) characters they've just entered.
Better to let them know early, in my opinion.

Private Sub Notes_Change()
If Len(Me.Notes.Text) > 1560 Then
DoCmd.Beep
'You can also put the MsgBox here if you must
Me.Notes.Text = Left(Me.Notes, 1560)
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Tru said:
Is there any way I can count the charaters in a memo field including
spaces.
I currently use the following procedure.

On Error GoTo Err_Form_BeforeUpdate
If Len(Me![Notes]) > 1560 Then
MsgBox "Your notes must be less than 1,560 characters.", vbInformation,
"Exceeded Field Limit"
Cancel = True
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

I want the user to have the ability to check the count before trying to
save
the record.
 
G

Guest

Change Event????
The change event fires after every character is entered.

Graham R Seach said:
What you've done is OK, but I'd be inclined to use the Change() event, so
the users know exactly when they have exceeded the limit. After all, your
users are going to be real amused when you finally tell them that you're
going to discard the last 500 (excess) characters they've just entered.
Better to let them know early, in my opinion.

Private Sub Notes_Change()
If Len(Me.Notes.Text) > 1560 Then
DoCmd.Beep
'You can also put the MsgBox here if you must
Me.Notes.Text = Left(Me.Notes, 1560)
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Tru said:
Is there any way I can count the charaters in a memo field including
spaces.
I currently use the following procedure.

On Error GoTo Err_Form_BeforeUpdate
If Len(Me![Notes]) > 1560 Then
MsgBox "Your notes must be less than 1,560 characters.", vbInformation,
"Exceeded Field Limit"
Cancel = True
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

I want the user to have the ability to check the count before trying to
save
the record.
 
G

Graham R Seach

....barada nicto.

<<The change event fires after every character is entered>>
That's right!

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Klatuu said:
Change Event????
The change event fires after every character is entered.

Graham R Seach said:
What you've done is OK, but I'd be inclined to use the Change() event, so
the users know exactly when they have exceeded the limit. After all, your
users are going to be real amused when you finally tell them that you're
going to discard the last 500 (excess) characters they've just entered.
Better to let them know early, in my opinion.

Private Sub Notes_Change()
If Len(Me.Notes.Text) > 1560 Then
DoCmd.Beep
'You can also put the MsgBox here if you must
Me.Notes.Text = Left(Me.Notes, 1560)
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Tru said:
Is there any way I can count the charaters in a memo field including
spaces.
I currently use the following procedure.

On Error GoTo Err_Form_BeforeUpdate
If Len(Me![Notes]) > 1560 Then
MsgBox "Your notes must be less than 1,560 characters.",
vbInformation,
"Exceeded Field Limit"
Cancel = True
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

I want the user to have the ability to check the count before trying to
save
the record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top