looping all combobox in frame2

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

looping all combobox in frame2

Post by sal21 »

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

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

Code: Select all

    Dim ctl As Control
    For Each ctl In Me.Frame2.Controls
        If TypeName(ctl) = "ComboBox" And Val(ctl.Tag) >= 1 Then
            ' Do something with ctl
            Debug.Print ctl.Name
        End If
    Next ctl
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: looping all combobox in frame2

Post by sal21 »

HansV wrote:
24 Nov 2021, 15:38

Code: Select all

        
    Dim ctl As Control
    For Each ctl In Me.Frame2.[b]Controls[/b]
        If TypeName(ctl) = "ComboBox" And Val(ctl.Tag) >= 1 Then
            ' Do something with ctl
            Debug.Print ctl.Name
        End If
    Next ctl
METHOD OR DATA MEMBER NOT FOUND in bold line For Each ctl In Me.Frame2.Controls

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

As you know, I don't have VB6. I tested on a userform in Excel. Does this work?

Code: Select all

    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.Container Is Me.Frame2 Then
            If TypeName(ctl) = "ComboBox" And Val(ctl.Tag) >= 1 Then
                ' Do something with ctl
                Debug.Print ctl.Name
            End If
        End If
    Next ctl
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: looping all combobox in frame2

Post by sal21 »

HansV wrote:
24 Nov 2021, 16:40
As you know, I don't have VB6. I tested on a userform in Excel. Does this work?

Code: Select all

    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.Container Is Me.Frame2 Then
            If TypeName(ctl) = "ComboBox" And Val(ctl.Tag) >= 1 Then
                ' Do something with ctl
                Debug.Print ctl.Name
            End If
        End If
    Next ctl
ERROR 438.in If ctl.Container Is Me.Frame2 Then

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

Try

If ctl.Container.Name = "Frame2" Then
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

Hello? Did this work?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: looping all combobox in frame2

Post by sal21 »

HansV wrote:
24 Nov 2021, 20:18
Hello? Did this work?
I cannot test now, Sorry.

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: looping all combobox in frame2

Post by sal21 »

HansV wrote:
24 Nov 2021, 20:18
Hello? Did this work?
on second loop for next same error 438 in: If ctl.Container.Name = "Frame2" Then !!!

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

Perhaps this?

Code: Select all

    Dim ctl As Control
    For Each ctl In Me.Controls
        If Not ctl.Container Is Nothing Then
            If ctl.Container.Name = "Frame2" Then
                If TypeName(ctl) = "ComboBox" And Val(ctl.Tag) >= 1 Then
                    ' Do something with ctl
                    Debug.Print ctl.Name
                End If
            End If
        End If
    Next ctl
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: looping all combobox in frame2

Post by HansV »

:scratch:
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: looping all combobox in frame2

Post by sal21 »

HansV wrote:
28 Nov 2021, 12:51
:scratch:
Sorry but I haven't tried it yet.