Textbox MaxLength Property Not Functioning

kjharve

Board Regular
Joined
Jan 4, 2006
Messages
206
Hi,

Has anyone had any problems with the MaxLength property not working? I built an application in Excel VBA for work, in it a text box needs to be limited to 255 characters as the information is eventually written to an Access database text field.

I have set the MaxLength property to 255 but the users are experiencing errors as they are not always stopped at 255 characters. I've tried to replicate this with my local version but have had no success.

I know I could do a work around by using "len" to check whether 255 characters has been exceeded, but, well frankly I don't see that it should be necessary!

Anyone had a similar issue or maybe have an explanation? The application is run on Excel '97.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

kjharve

Board Regular
Joined
Jan 4, 2006
Messages
206
Could it have anything to do with the MultiLine property set to True???
 

kjharve

Board Regular
Joined
Jan 4, 2006
Messages
206
Just to let you all know - I've solved it!

The MaxLength property cannot be relied upon when the MultiLine property is set to True.

This is because a carriage return character should be counted as two characters but for some reason is only counted as one for the purposes of the MaxLength property.

The impact of this is that if you have MaxLength set to 255 and you type 253 letters, pressing "enter" twice to separate to paragraphs, the actual character count is 257 (using len(textbox.text) ) Thus an error is generated when you attempt to write this string to a text field in a database!

Thanks for your input guys :wink:
 

Forum statistics

Threads
1,143,637
Messages
5,719,969
Members
422,252
Latest member
wannabegeek1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top