General information
Category:
Coding, syntax & commands
>>>>>Is it possible to detect which control has a tab order of "1" and to set focus to that control?
>>>>
>>>>lnMin = 9999
>>>>
>>>>FOR lnI = 1 TO _Screen.ActiveForm.ControlCount
>>>> IF _Screen.ActiveControl.TabIndex < lnMin
>>>> lnMin = _Screen.ActiveControl.TabIndex
>>>> loControl = _Screen.ActiveControl
>>>> ENDIF
>>>>ENDFOR
>>>>
>>>>loControl.SetFocus()
>>>
>>>How do you set the focus to a Label object? What if the object is disabled?
>>>
>>>Besides, you should use ActiveForm.Controls[lnI] instead of ActiveControl.
>>>
>>>Vlad
>>
>>Thanks to all of you for responding so quickly. I posted this message at work and by the time I got home... wow!
>>
>>Anyway, here's what I finally came up with:
>>
>>* set focus to first field
>>IF THISFORM.DEMode <> "VIEW" && ADD or EDIT
>> nCtlNo = 1
>> DO WHILE nCtlNo < 99
>> IF THIS.CONTROLS(nCtlNo).TABINDEX = 1
>> THIS.CONTROLS(nCtlNo).SETFOCUS
>> nCtlNo = 99 && jump out of loop
>> ELSE
>> nCtlNo = nCtlNo + 1
>> ENDIF
>> ENDDO
>>ENDIF
>>
>>Note that:
>> - All edit controls (textbox, combo box, checkbox, etc) are disabled in
>> VIEW mode and VIEW is the startup mode.
>> - I set the Tab Order to 1 for the 'first' field.
>> - this approach does not continue to test further once it finds the
>> 'first' field.
>> - my standard form has a two-page pageframe with page one for 'Data Entry'
>> and page two for 'List'
>> - this code is in the Refresh method of Page1
>
>1. What do you do if the 1st control with TabIndex = 1 is a label?
>2. You can use the This.ControlCount instead of 99 (99 will give you an error if you try to access the Controls[99] and you don't have 99 controls (the same for any other value > ControlCount, obviously))
>3. Are you sure you'll always have a TabIndex = 1?
>
>Vlad
Yeah, I'm pretty sure that the control with TabIndex=1 will always be the one I want. I always have to go in and set the tab order anyway so I just set the field I want to TabIndex=1.
I agree with point number 2.
Thanks again
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only