Nov 22, 2001 #1 enigma333 Programmer Jul 3, 2001 42 CA How can i determine the index of a control in the controls collection given the name.
Nov 22, 2001 #2 JustinEzequiel Programmer Jul 30, 2001 1,192 PH Option Explicit Private Sub Command1_Click() MsgBox CtrlIdx("Label1" End Sub Private Function CtrlIdx(ByVal sName As String) As Long Dim i As Long CtrlIdx = -1 For i = 0 To Controls.Count - 1 If Controls(i).Name = sName Then CtrlIdx = i Exit For End If Next i End Function Upvote 0 Downvote
Option Explicit Private Sub Command1_Click() MsgBox CtrlIdx("Label1" End Sub Private Function CtrlIdx(ByVal sName As String) As Long Dim i As Long CtrlIdx = -1 For i = 0 To Controls.Count - 1 If Controls(i).Name = sName Then CtrlIdx = i Exit For End If Next i End Function
Nov 23, 2001 Thread starter #3 enigma333 Programmer Jul 3, 2001 42 CA I was hoping to avoid looping through each one. There's no direct way for this? Upvote 0 Downvote