I'm new to MS Access forms. I have a combobox with 3 fields A, B, C. and a textbox. When the option B is selected the length of the characters in textbox should not exceed 3. I'm trying to write VBA code for this as below
Private Sub TEXTBOX_KeyPress(KeyAscii As Integer)
If [TEXTBOX].length && [COMBOBOX] = "B" Then
But the "length" field is not available in TEXTBOX, Could any one of you please let me know on how to resolve this.
If (Len(me.[TEXTBOX])) AND (me.[COMBOBOX] = "B") Then
Something to keep in mind though is when the key events fire. If I recall correctly, the keypress event happens when the user pushes the key down and holds it, but before the letter is appended to the end of the string. So I think you may need the keydown event, and you're also going to then want to cancel the keystroke, I think.
You can control the length of a field with the input mask if that's what you want? If I am interpreting what you are needing correctly then I think you need the following code in the AfterUpdate event for you combo box.
If [ComboBoxName] = "B" Then
If Len(Me.[TextBoxName]) > 3 Then Me.[TextBoxName] = Left(Me.[TextBoxName],3)
Me.[TextBoxName].InputMask = "AAA"