Character Length

kitty77

Registered User.
Local time
Today, 12:22
Joined
May 27, 2019
Messages
719
I'm using the following code to notify the user that they can only use a certain amount of characters.
How can I prevent them from continuing instead of just a text box?

If (Len(Msite) > 29) Then MsgBox "Text too long - Max 29 Characters", vbOKOnly
 
Which event are you using for this?
 
You can lock every other input until they do.

You can delete their input and make it a required field so nothing gets saved until they do it right.

You can pop up another form with just one input that feeds back into that one which won't go away until they input correctly.

You could truncate their input to the first 29 characters

You could have it send an email to you and you show up with a crowbar.
 
I just want a simple msgbox alerting them but not let them continue. Nothing super secure.
 
Investigate using the key down event

On my phone so air code

if len(mycontrol.text)>29 then char=asc(0)

Or set the field length to 29

you may also need code to allow for copy/paste
 
Cannot use after update because that happens after leaving the textbox not after entering data. Use on Change (happens after each keystroke) or as mentioned maybe the keydown.
The AfterUpdate event is triggered when a control or record is updated. Within a record, changed data in each control is updated when the control loses the focus or when the user presses Enter or Tab.
 
in the field's before update event, test the length entered, and cancel the event until they fix it.
Code:
if len(fieldname)>maxpermitted then
   msgbox "Sorry. Too long. The maximum length is " & maxpermitted & " characters. "
  cancel = true
  exit sub
end if
 

Users who are viewing this thread

Back
Top Bottom