maximum number of characters

  • Thread starter Thread starter -Obama
  • Start date Start date
O

-Obama

I am using access 97. How do I limit the number of character of a control in
a form at form level? Thanks.
 
-Obama,
you could do this in the table by adjusting the Field Size property for
that
field if it is a text field.

For a number field you could write a validation rule for the table like
this:
For a field called MyNbrTest
Validation rule: Len([MyNbrTest])<7
Validation text: No more than 6 digits allowed

Jeanette Cunningham
 
Thanks, Can I do it in a form level?


Jeanette Cunningham said:
-Obama,
you could do this in the table by adjusting the Field Size property for
that
field if it is a text field.

For a number field you could write a validation rule for the table like
this:
For a field called MyNbrTest
Validation rule: Len([MyNbrTest])<7
Validation text: No more than 6 digits allowed

Jeanette Cunningham

-Obama said:
I am using access 97. How do I limit the number of character of a control
in a form at form level? Thanks.
 
In the before update event for the control

If Len(Me.ControlName.Text) >6 Then
Msgbox "No more than 6 characters allowed"
Cancel = True
End If

Jeanette Cunningham

-Obama said:
Thanks, Can I do it in a form level?


Jeanette Cunningham said:
-Obama,
you could do this in the table by adjusting the Field Size property for
that
field if it is a text field.

For a number field you could write a validation rule for the table like
this:
For a field called MyNbrTest
Validation rule: Len([MyNbrTest])<7
Validation text: No more than 6 digits allowed

Jeanette Cunningham

-Obama said:
I am using access 97. How do I limit the number of character of a control
in a form at form level? Thanks.
 
Or you can use the KeyDown event to capture the keystrokes and, by using the
Len() function you can test for the length and then cancel any other
keystrokes if the length has been reached.

For example:

Private Sub MyTextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
If Len(Me.MyTextBoxName.Text) = 6 Then
KeyCode = 0
Msgbox "Only 6 characters allowed!", vbExclamation,"Max Length
Reached"
End If
End Sub

--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


-Obama said:
Thanks, Can I do it in a form level?


Jeanette Cunningham said:
-Obama,
you could do this in the table by adjusting the Field Size property for
that
field if it is a text field.

For a number field you could write a validation rule for the table like
this:
For a field called MyNbrTest
Validation rule: Len([MyNbrTest])<7
Validation text: No more than 6 digits allowed

Jeanette Cunningham

-Obama said:
I am using access 97. How do I limit the number of character of a control
in a form at form level? Thanks.
 
Or, if you simply want data entry to stop after a certain number of
characters are entered:

Private Sub YourTextBox_Change()
If Len(Me.YourTextBox.Text) = MaxChars + 1 Then
Me.YourTextBox.Text = Left(Me.YourTextBox.Text, MaxChars)
Me.YourTextBox.SelStart = Len(Me.YourTextBox)
End If
End Sub

where MaxChars is the maximum number of characters to be allowed.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

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

Back
Top