William Benson (VBACreations.Com)
vbacreations at gmail.com
Mon Jun 13 05:37:32 CDT 2011
I wanted to tie up a loose end. Thank you to those who offered insights along the way. I don't mean to contradict Robert but I have to say that results from my testing showed that any relationship between Tabindex and ColumnOrder is a shortlived one. Once a form has been put in Datasheet view, it is possible to void the relationship with either code or drag and drop. I also observed some other things which I will pass along, not sure if they are valid but this is how conditions appeared to me after hours of testing and trying to understand what the heck Access was doing under the hood. [In some situations I just threw my hands up and concluded results could not be predicted with any consistency] ColumnOrder is a property that seems to relate only to textboxes on a form. Don't test it for non-textboxes, test first that the control is a Textbox before trying to read the property or you will get a trappable runtime error. ColumnOrder is not exposed through the interface, only through VBA. ColumnOrder is readable any time; It is writeable only in Datasheet or Design view. Changes to TabIndex are not permanent unless the form gets (re)Saved Changes to ColumnIndex are "permanent" [caveat - an unstable ColumnOrder pattern can be overridden by Access when moving to Datasheet. Setting ColumnOrder with VBA may or may not be stable. It depends if it is set for every Textbox on a form, with no gaps. Toggling between Form and Datasheet Views could cause Access to reset ColumnOrders. If ColumnOrder happens to be zero for some controls and not for others, Access may position the former to the right of the latter, which is a bit counterintuitive. (0 is less than any other positive integer... so why right?? :-) ColumnOrder can be any integer from 0 to 32,767. Below is a useful function I created for testing Tabindex and ColumnOrder after I made changes manually or using VBA. Public Function ShowControlProperties() Dim frm As Form Dim colTxt As New Collection Dim Ctrl As Control Dim T As Access.TextBox For Each Ctrl In Screen.ActiveForm.Controls If TypeOf Ctrl Is Access.TextBox Then colTxt.Add Ctrl End If Next For Each T In colTxt Debug.Print T.Name & ": Tabindex=" & T.TabIndex & " | ColumnOrder = " & T.ColumnOrder Next End Function