get name of combobox in frame1

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

get name of combobox in frame1

Post by sal21 »

On vb6

my test code:

Code: Select all

...
Dim cCont As Control

    For Each cCont In Me.Controls.Frame1
        If TypeName(cCont) = "COMBOBOX" Then
            Stop
        End If
     Next cCont
     ...
i need only for frame1, in form have 2 frame.
Last edited by sal21 on 22 Apr 2021, 17:51, edited 1 time in total.

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

Re: get name of combobox in frame1

Post by HansV »

Why don't you respond to replies anymore, Sal?
Best wishes,
Hans

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

Re: get name of combobox in frame1

Post by sal21 »

HansV wrote:
22 Apr 2021, 17:27
Why don't you respond to replies anymore, Sal?
sorry, busy...
Now I'm doing it.

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

Re: get name of combobox in frame1

Post by HansV »

How about

Code: Select all

    Dim cCont As Control
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 And UCase(TypeName(cCont)) = "COMBOBOX" Then
            sName = cCont.Name
            Debug.Print sName
        End If
    Next cCont
Best wishes,
Hans

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

Re: get name of combobox in frame1

Post by sal21 »

HansV wrote:
22 Apr 2021, 17:55
How about

Code: Select all

    Dim cCont As Control
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 And UCase(TypeName(cCont)) = "COMBOBOX" Then
            sName = cCont.Name
            Debug.Print sName
        End If
    Next cCont
WORK FINE!

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

Re: get name of combobox in frame1

Post by sal21 »

sal21 wrote:
22 Apr 2021, 18:45
HansV wrote:
22 Apr 2021, 17:55
How about

Code: Select all

    Dim cCont As Control
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 And UCase(TypeName(cCont)) = "COMBOBOX" Then
            sName = cCont.Name
            Debug.Print sName
        End If
    Next cCont
WORK FINE!
HUMMMMM. possible to get also the index of combobox?
similar:

TG = CCONTR.Index

note:
dim TG as integer

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

Re: get name of combobox in frame1

Post by HansV »

You'll have to test that yourself - I don't have VB6.
If Index doesn't work, you could try

Code: Select all

    Dim cCont As Control
    Dim TG As Long
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 Then
            TG = TG + 1
            If UCase(TypeName(cCont)) = "COMBOBOX" Then
                sName = cCont.Name
                Debug.Print sName & ": " & TG
            End If
        End If
    Next cCont
Best wishes,
Hans

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

Re: get name of combobox in frame1

Post by sal21 »

HansV wrote:
22 Apr 2021, 19:24
You'll have to test that yourself - I don't have VB6.
If Index doesn't work, you could try

Code: Select all

    Dim cCont As Control
    Dim TG As Long
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 Then
            TG = TG + 1
            If UCase(TypeName(cCont)) = "COMBOBOX" Then
                sName = cCont.Name
                Debug.Print sName & ": " & TG
        End If
    Next cCont
Admit i need to use a sname as combobox object, possible?

for example:

with sname

for i ....

.additem value ....

next i

end with

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

Re: get name of combobox in frame1

Post by HansV »

No, sName is a String, not a control. You can either use

Code: Select all

    With Me.Controls(sName)
        ...
    End With
or use the variable cCont:

Code: Select all

    Dim cCont As Control
    Dim TG As Long
    Dim sName As String
    For Each cCont In Me.Controls
        If cCont.Container Is Me.Frame1 Then
            TG = TG + 1
            If UCase(TypeName(cCont)) = "COMBOBOX" Then
                sName = cCont.Name
                Exit For
            End If
        End If
    Next cCont
    ...
    With cCont
        ...
    End With
Best wishes,
Hans