[AccessD] SPAM-LOW: Re: Form Controls - Class implementation

jwcolby jwcolby at colbyconsulting.com
Tue Oct 27 19:50:44 CDT 2009


A.D.

I will address the issue of "double scanning" in the next email.

The problem with the code displaying the controls in incorrect order was simply that I didn't index 
in to the collection as was discussed previously - using cstr(ctl.TabIndex).  Thanks for pointing 
that out.

Your method of "pouring" them into the final collection works great though, and then they are 
already in the final collection in sorted order.  In my version, the controls are not in the 
collection sorted, they are in the collection in the order encountered and have to be retrieved in 
sorted order.

So I will sort them using your method then pull them out sorted just by iterating the collection.

To sort them as you are doing:

'
'Sorts the controls in mcolCtlsSorted into sorted order
'
Function mSortControls()
Dim ctl As Control
Dim intIndex As Integer
Dim col As Collection
     With mcolCtlsSorted
         If .Count Then  'Check that there are controls in mcolCtlsSorted
             Set col = New Collection
             For intIndex = 0 To .Count - 1      'Iterate through mcolCtlsSorted
                 col.Add .Item(CStr(intIndex))   'Copying the controls into the temp collection
             Next intIndex
         End If
     End With
     '
     'If there are any controls in the temp collection then
     'set the main collection to the temp collection
     If col.Count Then
         Set mcolCtlsSorted = col
     End If

End Function

'
'Iterate the collection of controls getting each control name
'and appending it to a string
'
Property Get pCtlNames() As String
Dim ctl As Control
Dim strCtlNames As String

     For Each ctl In mcolCtlsSorted
         strCtlNames = strCtlNames & vbTab & ctl.Name
     Next ctl
     pCtlNames = strCtlNames

End Property

John W. Colby
www.ColbyConsulting.com


A.D.Tejpal wrote:
> JC,
> 
>     Thanks for providing a nice class based solution so promptly. Your well 
> known command over classes deserves to be complimented.
> 
>     While conducting tests (Access 2003 desktop), it was found that listing 
> of controls on form sections as displayed in the message box, is not always 
> in keeping with the tab index. For example, if the tab index in form header 
> is altered in design view and the form re-opened after saving, the results 
> are not found consistent.
> 
>     It seems that while building the control collection in the class, 
> greater reliability could be achieved by pouring the contents of a temporary 
> class into the main one in the order of tab index.
> 
>     It would also appear that the extra round of iteration just for finding 
> tab controls and their pages could be eliminated.
> 
>     Suggested modified versions incorporating the points outlined above are 
> placed below, in the following sequence:
> 
>     (a) Class C_CtlsByTabIndex
>     (b) Class C_CtlsByTabIndexMaster
>     (c) Code in form's module
> 
> Best wishes,
> A.D. Tejpal
> ------------




More information about the AccessD mailing list