Hi Everyone,
I'm working with Text and Combo boxes on a Tabstrip in a Userform. I have multiple Tabs on which the user will input data and then click a button to write the data to various worksheets. So far so good. My problem is that because Tabstrips share the same controls I want to reset the data in the Text and Combo boxes to their default values each time the user moves to the next tab on the strip.
First prize (if possible), would be for code for it to happen automatically as the user clicks to moves from say Tab1 to Tab2 on the Tabstrip. Not sure if this is possible?
Second option is to have a reset button which I have been playing around with various codes, but I cant get it to reset to the controls default value.
Here's what I've tried so far:
That doesnt work because of the "DefaultValue" being incorrect. I tried = False or = True but it just writes those words into my text boxes of course. Using "" instead just leaves the boxes blank.
Next code I tried is this which resets to default values, so it works, but it jumps the Userform focus back to Tab1 each time. So if my user was on Tab1, and moves to Tab2 and hits the reset button, I need the focus to stay on Tab2, not jump back to Tab1. So maybe just an extra line of code is needed here to keep the focus on the current tab.
Any help would be greatly appreciated as I have many Tabs and controls to work with so using a Multipage isnt an option. Tabstrip will be the quickest option.
Thanks in advance
Pat
I'm working with Text and Combo boxes on a Tabstrip in a Userform. I have multiple Tabs on which the user will input data and then click a button to write the data to various worksheets. So far so good. My problem is that because Tabstrips share the same controls I want to reset the data in the Text and Combo boxes to their default values each time the user moves to the next tab on the strip.
First prize (if possible), would be for code for it to happen automatically as the user clicks to moves from say Tab1 to Tab2 on the Tabstrip. Not sure if this is possible?
Second option is to have a reset button which I have been playing around with various codes, but I cant get it to reset to the controls default value.
Here's what I've tried so far:
Code:
Private Sub Reset_Click()
' Dim x As Control
' For Each x In Me.Controls
' If TypeOf x Is MSForms.TextBox Then x.Value = DefaultValue
' Next
End Sub
That doesnt work because of the "DefaultValue" being incorrect. I tried = False or = True but it just writes those words into my text boxes of course. Using "" instead just leaves the boxes blank.
Next code I tried is this which resets to default values, so it works, but it jumps the Userform focus back to Tab1 each time. So if my user was on Tab1, and moves to Tab2 and hits the reset button, I need the focus to stay on Tab2, not jump back to Tab1. So maybe just an extra line of code is needed here to keep the focus on the current tab.
Code:
Private Sub Reset_Click()
Unload Me
UserForm1.Show
End Sub
Any help would be greatly appreciated as I have many Tabs and controls to work with so using a Multipage isnt an option. Tabstrip will be the quickest option.
Thanks in advance
Pat