Set focus on field not on active page of a multipage

  • Thread starter Thread starter cwrm4
  • Start date Start date
C

cwrm4

Hello -

I have a VBA form with a multipage control. When the user clicks the
SAVE button on the form (it's above the multipage), I need to validate
a number of fields on all 4 pages of the multipage control.

If a field fails its respective validation, I pop-up a msg box noting
the error and then Set Focus on that field.

However, if the field that I need to Set Focus on is not on the
"active" (i.e. shown) page of the multi-page at the time the user
clicks SAVE, I get an error. I have tried using the Multipage1.Value =
n to set the correct page before setting focus on the field, but still
get an error.

Any ideas?

Thanks
 
I couldn't reproduce it.

So just for demo purposes to test:

Multipage1
Page1 Textbox1
Page2 Textbox2
Page3 Textbox3

so I loop through all the controls and look for a blank textbox. When
found, I take the number from the right side of the textbox name, subtract 1
to get the page index (first page is zero) and assign it to the
multipage.value property, then set focus.

Private Sub CommandButton1_Click()
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
If Len(Trim(ctl.Value)) = 0 Then
n = Int(Right(ctl.Name, 1))
Me.MultiPage1.Value = n - 1
ctl.SetFocus
Exit For
End If
End If
Next
End Sub

Worked fine for me
 
If we are working with excel 2003 and the code you suggested are in Private
Sub MultiPage1_Change(), this simply do not work.
 
Back
Top