I have a multipage form that I want to use for setup for a data analysis macro. I want some textboxes to show a warning label if the user exits them without entering a valid value, so I used the textbox_exit() event to set the label to visible if the textbox doesn’t contain a valid value. The issue is that the focus always starts on the tab of the multipage, but whenever I click on a textbox, the focus always goes to one particular textbox for a moment before moving to the textbox I selected. The focus goes to the textbox I created first, regardless of name, position on the multipage or location of its code in the program. This sets off the warning label for that textbox, which I don’t want to have happening.
I reproduced it as simply as possible, here’s the code:
Option Explicit
Dim Cancel As Boolean
Private Sub Textbox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1 > 5 And TextBox1 < 10 Then
Label1.Visible = False
Else
Label1.Visible = True
End If
End Sub
Private Sub Textbox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox2 > 5 And TextBox2 < 10 Then
Label2.Visible = False
Else
Label2.Visible = True
End If
End Sub
Everything is on a multipage with two pages. The second one is empty. The first one has three textboxes and two labels. When I click on either of the other two boxes, the box that I made first focuses for a second and its warning label pops up.
Is there a way to get the focus to move directly, or is this just a fact of how VBA treats multipages? If so, any suggestions for another way to make this form?