Limit Character length with combo

tl mike

Registered User.
Local time
Today, 13:13
Joined
Sep 7, 2007
Messages
117
I am trying to set up a text box in which if I have a certian item selected in a combo box that it will be able to adjust the amount of characters that can be entered into a text box such as

I have a tblLabels
In which it has
LabelPK
LabelSize
CharacterLength

On the form will have a combo box to select which label size i need to use
and on that selection the form will only allow the characterlength that is associated with that label.
 
Set the Key Preview to YES for the form's Key Preview property and you can use the KeyPress event to limit it:
Code:
    If Len(YourTextBoxNameHere.Text) = Me.YourComboNumberHere Then
        KeyAscii = 0
    End If
 
Where does the form get what the charactlength is supposed to be?

I tried the above code with the characterlength showing and with the label name showing in the combo box but it didnt work.
 
Where does the form get what the charactlength is supposed to be?

I tried the above code with the characterlength showing and with the label name showing in the combo box but it didnt work.

The code that I gave you looks to the combo box for the value. If the bound field of the rowsource is the displayed column (not a hidden key), then it should work.
 
Heres my problem I would like to show in the combo the name of the label since most of the people using the db will only know it by the avery label size number.

What would you do because also when I change the bound field it works but it wont save because I have the two tables related via the PK of the labels and if I change it to the characterlength it wont work because some labels have the same characterlength but the amount of rows is different.

I do want to thank you for the help!
 
Never mind I about my question on setup I figured it out with having the characterlength show up on an not visable text box
 
Next problems

1. Now it wont let me enter info into any of the other text boxes on the form

2. How do I use set the code to do multiple text boxes

Set the Key Preview to YES for the form's Key Preview property and you can use the KeyPress event to limit it:

Code:
If Len(YourTextBoxNameHere.Text) = Me.YourComboNumberHere Then
KeyAscii = 0
End If
 
Last edited:
Next problems

1. Now it wont let me enter info into any of the other text boxes on the form
You didn't put it in the FORM's KeyPress event did you? It needs to be on the CONTROL's KeyPress event. The KeyPreview is the form property that needs to be changed from No to Yes, but the code goes in the control's event.

2. How do I use set the code to do multiple text boxes

Same as above, put your code in the KeyPress event for each control you want this on and make sure to change it to reflect the correct control.
 
Worked like a charm thank you very much !!!!!!!!!!!!!!!!!
 

Users who are viewing this thread

Back
Top Bottom