Consulting

Results 1 to 8 of 8

Thread: Find Form Controls with Value not set

  1. #1
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location

    Find Form Controls with Value not set

    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!

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    Why don't you post a sample file to illustrate your questions ?

  3. #3
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location
    Quote Originally Posted by snb View Post
    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
    Last edited by SamT; 06-02-2021 at 07:13 AM.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    ¿Por qué no publica un archivo de ejemplo para ilustrar sus preguntas?

  5. #5
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location

    Thumbs up

    Quote Originally Posted by snb View Post
    ¿Por qué no publica un archivo de ejemplo para ilustrar sus preguntas?
    i did

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    Last edited by SamT; 06-02-2021 at 10:08 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    You didn't: check what 'file' in English means.

  8. #8
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location
    Quote Originally Posted by atallpa View Post
    i did

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •