code to limit text length to variable characters in the same textbox - option button use

dss28

Board Regular
Joined
Sep 3, 2020
Messages
165
Office Version
  1. 2007
Platform
  1. Windows
I want a user to select option button which will control the text length in a text box.
Some users may fill e.g. text upto 200 characters, some to 400 characters etc. to describe an event in the same text box in a userform I have designed.
I do not have any code but can anybody suggest please. code or reference any thing.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I want a user to select option button which will control the text length in a text box.
Some users may fill e.g. text upto 200 characters, some to 400 characters etc. to describe an event in the same text box in a userform I have designed.
I do not have any code but can anybody suggest please. code or reference any thing.

i tried following code
i have a user form with three options for printing a form.
The user selects the format by choosing option button 1 or 2 or 3. it opens another userform "frmMEDForm"to fill various details.

if opt button 1 is selected, it changes one combo box in the "frmMEDForm" to choose 1 to 12 Sr. No. to fill upto 12 lines with 70 character limit, hides two of the three command buttons and displays only one required to print the form.

if opt button 2 is selected, it changes the same combo box to choose 1 to 6 Sr. No. to fill upto 6 lines with 200 character limit, ...

if opt button 3 is selected, it changes the same combo box to choose only one Sr. No. to fill 1 lines with 600 character limit, ...

every other aspect is working fine but just the combo box working...

After selecting opt button 1 first, combo box is empty , however it should show sr no. 1 to 12

Then if opt button 2 is selected, combo box shows 1 to 12 Sr No. but it should show 1 to 6 SrNo.

Then if option button 3 is selected it shows, 1 to 6 Sr No. and not just 1 Sr No. as it should be and so on.....

Some line to reset the combo box is missing but I dont know where to place it.

Request please guide to resolve.

the code is as follows:
VBA Code:
Private Sub opt1_Click()

If opt1.Value = True Then

frmMEDForm.txbDescription.MaxLength = 70

End If

frmMEDForm.cmdFinalizeXL.Visible = True
frmMEDForm.cmdFinalize.Visible = False
frmMEDForm.cmdFinalizeS.Visible = False

 frmMEDForm.Show
    
With frmMEDForm.cmbSrNo

    .AddItem "1"
    .AddItem "2"
   .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
    .AddItem "7"
    .AddItem "8"
    .AddItem "9"
    .AddItem "10"
    .AddItem "11"
    .AddItem "12"
    
End With
End Sub

Private Sub opt2_Click()

If opt2.Value = True Then

frmMEDForm.txbDescription.MaxLength = 150

End If

frmMEDForm.cmdFinalize.Visible = True
frmMEDForm.cmdFinalizeXL.Visible = False
frmMEDForm.cmdFinalizeS.Visible = False

 frmMEDForm.Show
    
With frmMEDForm.cmbSrNo

    .AddItem "1"
    .AddItem "2"
   .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
    
End With
End Sub


Private Sub opt3_Click()

If opt3.Value = True Then

frmMEDForm.txbDescription.MaxLength = 500

End If

frmMEDForm.cmdFinalizeS.Visible = True
frmMEDForm.cmdFinalizeXL.Visible = False
frmMEDForm.cmdFinalize.Visible = False

 frmMEDForm.Show
    
With frmMEDForm.cmbSrNo

    .AddItem "1"
    
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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
Back
Top