I have a field set as a memo data type as I need to capture a reasonable sized comment; however, memo allows entire essays to be entered. Any ideas as to how I can limit the quantity of text entered to say 750 characters?
I have a field set as a memo data type as I need to capture a reasonable sized comment; however, memo allows entire essays to be entered. Any ideas as to how I can limit the quantity of text entered to say 750 characters?
In the KeyPress event of the text box used to enter to that field you can use code like this:
Code:If Len(Me.YourControlName.Text) = 750 Then KeyAscii = 0 Msgbox "You have reached the limit of characters you can type here.", vbInformation, "Limit Reached" End If
Really appreciate the suggestion but can't get it to work. When I enter the code into the expression builder I get a message saying, 'The expression you entered contains Invalid syntax'. I don't really do much coding but get the logic of the code. I assume I'm substituting the control name incorrectly. The textbox on the form is named Statement.
I've entered,
If Len(Me.statement.Text) = 750 Then
KeyAscii = 0
Msgbox "You have reached the limit of characters you can type here.", vbInformation, "Limit Reached"
End If
I've also tried,
If Len(Me.[statement].Text) = 750 Then
KeyAscii = 0
Msgbox "You have reached the limit of characters you can type here.", vbInformation, "Limit Reached"
End If
Same error message both times. Any suggestions?
First off, are you typing this in the actual VBA window? It doesn't seem like you are. When you click in the KEYDOWN event property of the text box named "statement" are you selecting [Event Procedure] from the drop down and then clicking the Ellipsis (...) to open the VBA window?
Was pressing the 3 elipses but then expression builder rather than code builder [told you I don't do coding]. Tried through the code builder and it now works perfectly.
Brilliant! You are a top man Bob. Thanks!