Limit characters entered in an input box....

lukeshuttlewood

Board Regular
Joined
Jul 27, 2004
Messages
90
Hi,

Is it possible to limit the amount of characters entered in to an input box in with older versions of VBA? eg Pre 2003?

In 2003 the 'MaxLength = X' feature works but not in 2000. Any ideas?


Rich (BB code):
buyercomments = InputBox("Comments Please", MaxLength = 255, buyercomments)


I know I could use a user form to limit characters but I encountered a problem with that too.....what code is needed to transfer the contents of a textbox in one form to a string dimension in a seperate form?

eg with 'Comments as string' in frmMain

Rich (BB code):
frmMain.Comments = frmComments.txtComment.text

but i recieve method not found error.


Cheers
Luke
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

my first idea was this
Code:
Sub test()
Do
buyercomments = InputBox("Comments Please", "title", buyercomments)
'activate next line to check
'MsgBox Len(buyercomments)
If Len(buyercomments) > 255 Then MsgBox "warning"
Loop While Len(buyercomments) > 255
End Sub
but when pasting very long strings I didn't get the warning

so I tried this, just clicked "OK" in the inputbox
Code:
Sub inputbox_maxlenght()
Dim teststring

teststring = Application.Rept("0123456789", 30)
MsgBox Len(teststring)
MsgBox Len(InputBox("Comments Please", "title", teststring))
End Sub
length seems to be restricted to 254: not for you ?

kind regards,
Erik
 

Forum statistics

Threads
1,136,878
Messages
5,678,315
Members
419,754
Latest member
LordEddard

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