Assuming all the controls you want to check are Textboxes.
If not tell me what type controls do we need to check.
Controls are like:
Textbox's
Comboboxes
Check Boxes
Listboxes
Code:Private Sub CommandButton1_Click() 'Modified 10/3/2018 1:49:35 AM EDT Dim ctrl As MSForms.Control Dim x As Long x = 0 For Each ctrl In Me.Controls Select Case True Case TypeOf ctrl Is MSForms.TextBox If ctrl.Value <> "" Then x = x + 1 End Select Next ctrl If x > 0 Then ans = MsgBox("Are you sure you want to close? All previously entered data will be lost.", vbYesNo) If ans = vbYes Then: Unload Me Else Unload Me End If End Sub
Like this thread? Share it with others