Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the
Originally Posted by luca90
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).
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.
Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the
Originally Posted by luca90
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.
Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the
Originally Posted by Elroy
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.
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.
Re: i need to loop all combobox in frame2 in a form and get the .tag value... if the
Originally Posted by Eduardo-
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.