PDA

View Full Version : [SOLVED:] How to select dynamic multipage tab please?



kestrel1306
07-24-2017, 04:00 PM
Hi fellow VBA'ers

So...

I have a userform with 8 tabs.

To make life easier for my users I want hide hide three of them, unless the are required (reducing clutter).

But.

At the end I do error checking to ensure that some mandatory fields have been completed.

I used to be able to select the blank field by using

UserForm8.MP1.Value = 5
UserForm8.MP2.Value = 2
UserForm8.Frame14.SetFocus

Now I can't use that method as the value will change depending on how many tabs are displayed.

I've tried


UserForm8.MP1.pages ("page6)
UserForm8.MP2.Value = 2
UserForm8.Frame14.SetFocus



But it gives an error, I tried looping through to get an index number with no luck either.

Your help would be greatly appreciated thanks :-)


Regards
Kes

gmaxey
07-24-2017, 07:01 PM
Well obviously you can't set the focus on a control positioned on a hidden page tab.


Private Sub UserForm_Initialize()
Dim lngIndex As Long
With MultiPage1
.Value = 0
.Pages(5).Visible = False
.Pages(6).Visible = False
.Pages(7).Visible = False
On Error GoTo Err_Enabler
For lngIndex = 0 To MultiPage1.Pages.Count
If TextBox1 = vbNullString Then
TextBox1.SetFocus
Exit For
End If
Next
End With
lbl_Exit:
Exit Sub
Err_Enabler:
lngIndex = lngIndex + 1
MultiPage1.Value = lngIndex
Resume
End Sub

kestrel1306
07-24-2017, 11:12 PM
Hi Greg,

Sorry for my poor explanation.

The tabs will be visible as they will be turned on by the end users.

So I will be going to a visible tab for the validation bit.

Does that make any difference to you answer?

Thanks
Kes

gmaxey
07-25-2017, 05:36 AM
Not really. The point is that to set focus to a control in a multipage control is that control's parent page must be the enabled page. So it Textbox2 is located on Multipage1.Pages(3) then Page 3 has to be the enabled page.

kestrel1306
07-26-2017, 06:45 PM
solved.

Thank you very much!

Paul_Hossler
07-29-2017, 06:08 AM
solved.

Thank you very much!

You can mark your thread [Solved] by using [Thread Tools] on the menu above your first post