Changing TabStop code to True

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
My UserForm displays 41 cell values from Sheet1. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I’ve included a CommandButton that allows me to add new data to Sheet1 from the UserForm<o:p></o:p>
<o:p></o:p>
Can my code be simplified to make all TextBox TabStop=True? <o:p></o:p>
<o:p></o:p>
Code:
[FONT=Verdana][SIZE=1]Private Sub CommandButton3_Click()<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With TextBox1<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If TextBox1.Visible = False Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]TextBox1.Visible = True<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With Label1<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If Label1.Visible = False Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]Label1.Visible = True<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With TextBox2<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If TextBox2.Visible = False Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]TextBox2.Visible = True<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With Label2<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If Label2.Visible = False Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]Label2.Visible = True<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With ComboBox1<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If ComboBox1.Visible = True Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]ComboBox1.Visible = False<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]With TextBox3<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]If TextBox3.TabStop = False Then<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]TextBox3.TabStop = True<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End If<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End With<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]TextBox1.SetFocus<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]<o:p></o:p>[/SIZE][/FONT]
[FONT=Verdana][SIZE=1]End Sub<o:p></o:p>[/SIZE][/FONT]
<o:p></o:p>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Is it the TabStop property that you want to set or the Visible property? Why are you repeating the names of your controls inside a With construct?
 
Upvote 0
Andrew,

I'm doing both.

CommandButton3 makes ComboBox1 invisible...and TextBoxes1 & 2 visible.
In effect, the TextBoxes replace the ComboBox on the UserForm.

So, by clicking on CommandButton3, the form is converted from a data display to a data entry form.

All of the TabStops are set to False when in data display mode.
I need all the TabStops to be set to True when in data entry mode.

The reason I have all those "Withs" is because I don't know any better. :eeek:
 
Upvote 0
Why TabStop?

Setting that to False is not going to prevent the user changing/entering something in the texbox - it'll just stop them being able to tab to it.

Why not enable/disable the textboxes as required?
Code:
' Enable all textboxes for data entry
For I = 1 To 41 
    Me.Controls("TextBox" & I).Enabled = True
Next I
You can still put values in disabled textboxes, though they will be greyed out.

You could use Locked if you don't want them greyed out.
 
Upvote 0
Why TabStop?

Setting that to False is not going to prevent the user changing/entering something in the texbox - it'll just stop them being able to tab to it.

Why not enable/disable the textboxes as required?

You can still put values in disabled textboxes, though they will be greyed out.

You could use Locked if you don't want them greyed out.

Great idea! I never thought of that. Thanks Norie!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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