Results 1 to 9 of 9

Thread: i need to loop all combobox in frame2 in a form and get the .tag value... if the .tag

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    i need to loop all combobox in frame2 in a form and get the .tag value... if the .tag

    i need to loop all combobox in frame2 in a form and get the .tag value from each combobox where combobox.tag value is >=1

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by luca90 View Post
    i need to loop all combobox in frame2 in a form and get the .tag value from each combobox where combobox.tag value is >=1
    This sounds like more homework, but I thought it'd be fun so I did it.

    EDIT: I suppose I could have also printed the .Tag value in my Debug.Print statement, but Luca should be able to figure that one out (hopefully).
    Attached Files Attached Files
    Last edited by Elroy; Nov 24th, 2021 at 12:31 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by Elroy View Post
    This sounds like more homework, but I thought it'd be fun so I did it.

    EDIT: I suppose I could have also printed the .Tag value in my Debug.Print statement, but Luca should be able to figure that one out (hopefully).
    I cannot test now, but this code work... As usual. Tks

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by Elroy View Post
    This sounds like more homework, but I thought it'd be fun so I did it.

    EDIT: I suppose I could have also printed the .Tag value in my Debug.Print statement, but Luca should be able to figure that one out (hopefully).
    in i = v.Index

    error 343, object not an array

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by luca90 View Post
    in i = v.Index

    error 343, object not an array
    Luca, I'm not sure what you're getting at. Here, I'll post my code:

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
    
        ' This is the only place where specific ComboBoxes are addressed.
    
        Combo1.Tag = 5
        Combo3.Tag = 5
        ComboArray(2).Tag = 5
        '
        Combo5.Tag = 5 ' Not in Frame2.
    End Sub
    
    Private Sub Form_Click()
        Dim c As Collection
        Set c = FindCombosInFrame2WithTagGeOne
        Dim v As Variant
    
        ' List the ComboBoxes found.
        Debug.Print "Comboboxes in Frame2 with Tag value >= 1:"
        For Each v In c
            If HasIndex(v) Then
                Debug.Print v.Name & "(" & v.Index & ")"
            Else
                Debug.Print v.Name
            End If
        Next
    End Sub
    
    Private Function FindCombosInFrame2WithTagGeOne() As Collection
        Dim ctl As Control
        Set FindCombosInFrame2WithTagGeOne = New Collection
        For Each ctl In Me.Controls
            If TypeName(ctl) = "ComboBox" Then
                If ctl.Container.Name = "Frame2" Then ' Hardcoded per specifications.
                    If Val(ctl.Tag) >= 1 Then
                        FindCombosInFrame2WithTagGeOne.Add ctl
                    End If
                End If
            End If
        Next
    End Function
    
    Private Function HasIndex(v As Variant) As Boolean
        On Error GoTo NoIndex ' <---- Error trapping!!!
        Dim i As Long
        i = v.Index
        HasIndex = True
    NoIndex:
    End Function
    
    
    The only place where I've got a line like you quoted is inside of error trapping used just to determine if it's a control array or not.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by Elroy View Post
    Luca, I'm not sure what you're getting at. Here, I'll post my code:

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
    
        ' This is the only place where specific ComboBoxes are addressed.
    
        Combo1.Tag = 5
        Combo3.Tag = 5
        ComboArray(2).Tag = 5
        '
        Combo5.Tag = 5 ' Not in Frame2.
    End Sub
    
    Private Sub Form_Click()
        Dim c As Collection
        Set c = FindCombosInFrame2WithTagGeOne
        Dim v As Variant
    
        ' List the ComboBoxes found.
        Debug.Print "Comboboxes in Frame2 with Tag value >= 1:"
        For Each v In c
            If HasIndex(v) Then
                Debug.Print v.Name & "(" & v.Index & ")"
            Else
                Debug.Print v.Name
            End If
        Next
    End Sub
    
    Private Function FindCombosInFrame2WithTagGeOne() As Collection
        Dim ctl As Control
        Set FindCombosInFrame2WithTagGeOne = New Collection
        For Each ctl In Me.Controls
            If TypeName(ctl) = "ComboBox" Then
                If ctl.Container.Name = "Frame2" Then ' Hardcoded per specifications.
                    If Val(ctl.Tag) >= 1 Then
                        FindCombosInFrame2WithTagGeOne.Add ctl
                    End If
                End If
            End If
        Next
    End Function
    
    Private Function HasIndex(v As Variant) As Boolean
        On Error GoTo NoIndex ' <---- Error trapping!!!
        Dim i As Long
        i = v.Index
        HasIndex = True
    NoIndex:
    End Function
    
    
    The only place where I've got a line like you quoted is inside of error trapping used just to determine if it's a control array or not.
    Here my form. the test is on frame2
    Attached Files Attached Files

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Your test project works fine for me ... so IDK.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by Elroy View Post
    Your test project works fine for me ... so IDK.
    He (or she?) must have the IDE configured to halt on all errors.

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the

    Quote Originally Posted by Eduardo- View Post
    He (or she?) must have the IDE configured to halt on all errors.

    Ahh, good point. I didn't think about that. Luca, I always have my IDE set to break only on unhandled errors. On the menu ---> Tools ---> Options ---> General tab ---> Break on unhandled errors. I suppose there is one, but I've never had a reason to break on "handled" errors (which is what "Break on ALL errors" will do).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Posting Permissions

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



Click Here to Expand Forum to Full Width