MultiPage OnExit Event

stirlingmw1

Board Regular
Joined
Jun 17, 2016
Messages
53
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
Morning all

I have a Userform with a MuliPage control. On one of the pages (8) I have 240 Textboxes (Textbox 166 to 405) that the operator has the option to add data. Once data has been added the user selects CommandButton (SubmitData). on selecting this command button the data that has been added to the textboxes is then added to "Data" Worksheet. I am trying to add some code that identifies if any data has been added to any of the 240 textboxes and if so prompts the user to select SubmitData if they already haven't if the user tries to exit MultiPage 8.

Any ideas?

Thanks Steve
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,
following is an untested idea which hopefully will go in right direction to do what you want

VBA Code:
Private Sub MultiPage1_Change()
    Const PageName As String = "Page8"
    With Me.MultiPage1
        If .SelectedItem.Name = PageName Then
            .Tag = PageName
        ElseIf .Tag = PageName And .SelectedItem.Name <> .Tag Then
'check textboxes for any data entry
        For i = 166 To 405
            If Len(.Pages(PageName).Controls("TextBox" & i).Value) > 0 Then
'inform user
                MsgBox "Please Submit Values In " & .Pages(PageName).Caption & Chr(10) & _
                        "Before Continuing", 16, "Submit Data"
'optional re-activate tab
                '.Value = .Pages(PageName).Index
            Exit For
            End If
        Next
        Else
        .Tag = ""
        End If
   End With
End Sub

In commandbutton code you need to add a line to clear the Tag
VBA Code:
Private Sub SubmitData_Click()
    Me.MultiPage1.Tag = ""
    
    'rest of code
End Sub

as stated, this is just an idea, you will need to adapt to meet specific project need as required

Dave
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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