Set focus to field on userform and activate relevant multipage

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to set the focus to a field which is empty;

Code:
For Each ctl In Me.Controls
If TypeName(ctl) Like "Text*" Or TypeName(ctl) Like "Combo*" Then
If ctl.Value = "" Then
Call MsgBox("You have fields with mandatory data missing", vbCritical, "Missing data")
ctl.SetFocus
Exit Sub
End If
End If
Next ctl

The issue I have is that all of the fields are on 4 different multipage pages, so I need a way to activate the relevant page once an empty field is found if anyone can help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

probably a cleaner way but try

Code:
Dim ctrl As Control
    Dim Page As Long
    
    With Me.MultiPage1
        For Page = 0 To .Pages.Count - 1
            For Each ctrl In .Pages(Page).Controls
                If TypeName(ctrl) Like "Text*" Or TypeName(ctrl) Like "Combo*" Then
                    If ctrl.Value = "" Then
                        .Value = Page
                        MsgBox "You have fields with mandatory data missing", vbCritical, "Missing data"
                        ctrl.SetFocus
                        Exit Sub
                    End If
                End If
            Next ctrl
        Next Page
    End With

Dave
 
Upvote 0

Forum statistics

Threads
1,224,900
Messages
6,181,632
Members
453,059
Latest member
jkevin

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