Henry_Harris
asked on
Order of Controls in Controls Collection
Is it possible to predict the order of controls when looping through the controls collection.
Order on the form would be preferred or else Tab Order will suffice.
My code is attached
Order on the form would be preferred or else Tab Order will suffice.
My code is attached
Public Function CheckForEmptyControls()
CheckForEmptyControls = True
With CodeContextObject
Dim ctl As Control
Dim strMissingEntryMessage As String
strMissingEntryMessage = ""
For Each ctl In .Controls
If ctl.Visible And _
(Left(ctl.Name, 3) = "txt" Or Left(ctl.Name, 3) = "cbo") _
And ctl.Name <> "txtRelease" And ctl.Name <> "ID" And IsNull(ctl) Then
strMissingEntryMessage = strMissingEntryMessage & Chr(13) & Chr(10) & " " & ctl.Tag
End If
Next ctl
If strMissingEntryMessage <> "" Then
CheckForEmptyControls = False
If MsgBox("The following needs to be completed:" & Chr(13) & Chr(10) & strMissingEntryMessage, _
vbRetryCancel, strMsgBoxTitle & ": Completing Form " & .Name) = vbCancel Then
.Undo
.cmdCloseForm.SetFocus
.cmdSaveRecord.Enabled = False
End If
End If
End With
End Function
ASKER
Thanks for your post, which I understand
As you can see from my code snippet, I will be displaying amessage that lists the Tags of the fields that have not been completed. I would prefer the order that the Msgbox message is constructed to be in the same order as the controls on the form. Constructing the message in Tab order would allow me change controls and maintain a predictable order of controls in the message.
As you can see from my code snippet, I will be displaying amessage that lists the Tags of the fields that have not been completed. I would prefer the order that the Msgbox message is constructed to be in the same order as the controls on the form. Constructing the message in Tab order would allow me change controls and maintain a predictable order of controls in the message.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution is nearly perforect for what I need.
Thanks very much.
Thanks very much.
Control2
Control3
Control1
What's your end goal here? Why would it matter what physical order the Controls collection would be in? There may be other ways to accomplish what you're after, but we'd need to know more about it.