sorting controls ???

  • Thread starter Thread starter rmanchu
  • Start date Start date
R

rmanchu

hi

is there a guaranteed order for:
For Each ctl in myForm.Controls

if i wanted to display the the values in forms' controls in a
particular order, waht's the best way to do it? ps: the .Tag property
is already taken

also

whats the property of a control that retrieves its associated Label ?

thanx
riyaz
 
AFAIK, the controls are returned in the order in which they were added to
the form.

I don't understand, though, what you're trying to do: I don't see how you'd
use this approach to "display the the values in forms' controls in a
particular order".

To get the label associated with a control, look in its Controls collection.
For example, if you've got a text box named txtData, its label (if it has
one associated with it) should be Me.txtData.Controls(0).Name

Error 2467 will be raised if you try to refer to the Controls collection for
a control that doesn't have a label associated with it.
 
AFAIK, the controls are returned in the order in which they were added
to the form.

i don't think i can rely on this approach. i'd be adding n deleting
controls all the time. :)
I don't understand, though, what you're trying to do: I don't see how you'd
use this approach to "display the the values in forms' controls in a
particular order".

i'm writing a generic procedure for many forms that displays the
current record. i don't want "FirstName" displayed, then his "Salary"
and then some more and then "LastName" coming up :)

i wud like to be able to control the order in which the fields
(controls on firm) in the record (form) eg: firstname, lastname, dob,
age GUARANTEED in that order.

help

thanx
riyaz
 
(e-mail address removed) wrote in message
i don't think i can rely on this approach. i'd be adding n deleting
controls all the time. :)


i'm writing a generic procedure for many forms that displays the
current record. i don't want "FirstName" displayed, then his "Salary"
and then some more and then "LastName" coming up :)

i wud like to be able to control the order in which the fields
(controls on firm) in the record (form) eg: firstname, lastname, dob,
age GUARANTEED in that order.

help

thanx
riyaz

Perhaps just using a naming convention involving numbers might do? Say
txt1, txt2, txt3 ... txt10

for lngcount = 1 to 10
debug.print me.controls("txt" & cstr(lngcount)).value
next lngcount
 
Put incrementing values in the Tag property of the controls so that you can
read the Tag property and then "sort" based on that value.
 
many forms (in current use), controls already named differently.
renaming is not an option. :(

thanx
 
tag already taken

my (not so) bright idea

dim vars(1 to frm.conttrols.count) as string
for each ctl in frm.controls
if ctl has tabindex
vars(ctl.tabindex) = ctl.value
concatenated vars

any ideas?
 
A tag can contain more than one piece of information. Think of it similarly
to a "cookie", where various values are separated by a delimiter
(semicolon). For example:

Name=the name;Type=the type;Color=the color

Just put the concatenated data in the Tag property and then have a function
that parses it and finds the value you seek, based on the "identifier" that
you send to the function. This process is used in VBScript and web pages all
the time for parsing out various "cookie" values.
 
Ken said:
A tag can contain more than one piece of information. Think of it similarly
to a "cookie", where various values are separated by a delimiter
(semicolon). For example:

Name=the name;Type=the type;Color=the color

i know. but there is existing code that uses the tag value and i really
don't want to delve into whether appending to tag will break the code
or not. and i'm not talking about one form either :( - about 20 atleast

thanx, riyaz
 
OK. I went back to what you'd posted just before (reproduced below), but
must admit that I do not understand what you're wanting to do?

--
my (not so) bright idea

dim vars(1 to frm.conttrols.count) as string
for each ctl in frm.controls
if ctl has tabindex
vars(ctl.tabindex) = ctl.value
concatenated vars
--

Are you wanting to use the Tab Order index number? That would be helpful
only if, as you add and delete controls, that you ensure that you have a
correct tab order at all times.

If this is what you want to use, then yes it's possible to use the tab
index. Here is a subroutine that I use to move the focus to the control that
is next in the tab order sequence (it shows how you can use the TabIndex
property):

' **********************************
' * Sub MoveFocusToNextControl *
' **********************************

Public Sub MoveFocusToNextControl(xfrmFormName As Form, xctlCurrentControl
As Control, _
xblnOnlyTabStopYes As Boolean)
' *** THIS SUBROUTINE MOVES THE FOCUS TO THE NEXT CONTROL IN THE TAB ORDER.
' *** IF xblnOnlyTabStopYes IS TRUE, THEN THE NEXT CONTROL MUST HAVE A TAB
' *** STOP VALUE OF "TRUE" AND MUST BE VISIBLE AND MUST BE ENABLED, ELSE
' *** THE SUBROUTINE GOES TO THE NEXT CONTROL.
' *** NOTE: THIS SUBROUTINE WILL NOT "CYCLE BACK" TO TAB INDEX OF 0, SO
' *** DO NOT USE THIS SUBROUTINE IF THERE IS NO CONTROL CAPABLE OF RECEIVING
THE
' *** FOCUS IN THE TAB ORDER SEQUENCE AFTER THE CURRENT CONTROL!!!!!
' Code by Kenneth D. Snell, 26 May 2005

Dim xctl As Control
Dim lngTab As Long, lngNewTab As Long

On Error Resume Next

' Move focus to the next control in the tab order (if that control has a Tab
Stop
' property of True)
lngTab = xctlCurrentControl.TabIndex + 1

MyLoopLabel:
For Each xctl In xfrmFormName.Controls
lngNewTab = xctl.TabIndex
' An error will occur if the control does not have a TabIndex property;
' skip over those controls.
If Err.Number = 0 Then
If lngNewTab = lngTab Then
If (xctl.TabStop = True Or xblnOnlyTabStopYes = False) And _
xctl.Visible = True And xctl.Enabled = True Then
xctl.SetFocus
Exit For
Else
lngTab = lngTab + 1
GoTo MyLoopLabel
End If
End If
Else
Err.Clear
End If
Next xctl
Set xctl = Nothing
Err.Clear
End Sub
 
just build a table....and insert your field names......

autonumber myfield
327 FirstName
328 LastName

etc. etc. etc...

We really don't care about the auotnumber field...except it would be used to
keep the SAME order that you enter the list for the particular form.

So, just build a table. The only real question is if you have to do this for
one form....or many....

if for many...then add a form/table column to the above.....
 
Back
Top