View Full Version : Find Form Controls with Value not set
atallpa
06-02-2021, 04:42 AM
Hello i have a form with three multipage and i want to check all comboboxes but not at once so i want to check value ="" of the first six and the repeat the code for the 7th to 25th and so on but when i nest the for i into the for each no works and when i do the same but opposite the for each in the for i doesn work as well.
It has sence to do that or theres another way ?
thank you a lot!
Why don't you post a sample file to illustrate your questions ?
atallpa
06-02-2021, 05:41 AM
Why don't you post a sample file to illustrate your questions ?
sorry u re right
Private Sub MultiPage1_Change()
Dim i As Integer 
dim contr as control
    For Each Control In UserForm1.Controls
           If TypeName(contr) = "ComboBox" Then
                  For i = 1 To 2
                      If Controls("ComboBox" & i).Value = "" Then
                              MsgBox " you have incomplete answers"
                      End If
                  Next i
             End If
          Next
End Sub
¿Por qué no publica un archivo de ejemplo para ilustrar sus preguntas?
atallpa
06-02-2021, 06:39 AM
¿Por qué no publica un archivo de ejemplo para ilustrar sus preguntas?
 i did  :arrowu:
THis won't work: Wrong Event
Private Sub MultiPage1_Change()
dim contr as object
    For Each contr In UserForm1.Controls
       If TypeName(contr) = "ComboBox" Then
            If contr.ListIndex = -1 Then  
                 MsgBox " you have incomplete answers"
                 Exit Sub
           End If
       End If
   Next
End Sub
Try this
Option Explicit
Private Sub CommandButtonX_Click()
'Replace CommandButtonX with your button name.
Dim Pg As Object, Ctrl As Object
    For Each Pg In MultiPage1.Pages
        For Each Ctrl In Pg.Controls
            If TypeName(Ctrl) = "ComboBox" Then
                If Ctrl.ListIndex = -1 Then
                    MsgBox "You have incomplete answers on Page " & Pg.Caption
                    Pg.SetFocus 'Redundant
                    Ctrl.SetFocus
                    Exit Sub
                End If
            End If
        Next
    Next
End Sub
Use the Go Advanced button to upload attachments
You didn't:  check what 'file' in English means.
atallpa
06-03-2021, 02:25 AM
i did  :arrowu:
Amazing thank you very much for your help i didnt tried but i believe it will work, sometimes happens that i dont know how to reference certain objects inside other objects, i dont know in programming how does it call but for me its the most difficult part to learn a language.
Greetings and thank you.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.