...is the problem. One way or the other you have tell the code which Control to Tab to. You might want to include something using the Tag property of the Control. Nothing else comes to mind.I want to tell the code to go to the next control in the tab order (without having to specify which control that is)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.TabIndex = Me.ActiveControl.TabIndex + 1 Then
ctl.SetFocus
Exit For
End If
Oops, sorry, my misunderstanding... Try looking at the TabIndex Property. The code below (untested) should determine the next Tab Stop, with some adapting it might give you what you need...
Code:Dim ctl As Control For Each ctl In Me.Controls If ctl.TabIndex = Me.ActiveControl.TabIndex + 1 Then ctl.SetFocus Exit For End If
If InStr(1, Me.ActiveControl.Tag, "ExpandCollapseSection1") <> 0 Then
For Each ctl In Me.Controls
If Not InStr(1, ctl.Tag, "ExpandCollapseSection1") <> 0 Then
If ctl.Visible = True Then
ctl.SetFocus
Exit For
End If
End If
Next
End If
If focus is in one of the 'to be collapsed' controls, then
for every control in the form
If the control is not one of the the 'to be collapsed' controls, then
If it is visible, then
Set Focus to this control
Stop the loop here after you set focus to a control
Yeah, I don't know, that is what I am trying to esplain, I have not given thought as to the *how* part.
If InStr(1, Me.ActiveControl.Tag, "ExpandCollapseSection1") <> 0 Then
For Each ctl In Me.Controls
[COLOR="Red"]If ctl.TabIndex = Me.ActiveControl.TabIndex + 1 Then[/COLOR]
ctl.SetFocus
If Not InStr(1, ctl.Tag, "ExpandCollapseSection1") <> 0 Then
If ctl.Visible = True Then
Exit For
End If
End If
End If
Next
End If
If the active control is in the 'to be collapsed' section, then
For each control in this form
[COLOR="red"]If this control's tab index is 1 greater than the active control's tab index, then[/COLOR]
Set focus to this control
If this control is NOT in the 'to be collapsed' section, then
If this control is visible, then
Exit the for command (loop) here
End If
End If
End If
Next
End If
private sub findnexttab()
dim nearest as single
dim ctrl as control
dim ctrlname as string
lowest=me.insideheight 'just set a max value to measure against
ctrlname=""
for each ctrl in me.controls
if ctrl.controltype<>aclabel then 'labels can't have focus
if ctrl.top>(me.activecontrol.top+me.activecontrol.height) and ctrl.top-me.activecontrol.top<nearest and ctrl.visible=true then 'this is the the nearest visible so far
ctrlname=ctrl.name 'set the name of the control to have the focus
nearest=ctrl.top-me.activecontrol.top 'reduce nearest to lower figure
end if
end if
next
if ctrlname<>"" then me(ctrlname).setfocus 'otherwise do nothing
end sub
The reason why your code is failing is that not all controls have a tabindex - for example labels.If InStr(1, Me.ActiveControl.Tag, "ExpandCollapseSection1") <> 0 Then
For Each ctl In Me.Controls
If ctl.TabIndex = Me.ActiveControl.TabIndex + 1 Then
The reason why your code is failing is that not all controls have a tabindex - for example labels.
If ctl.ControlType = acTextBox Then
If ctl.TabStop = True Then
on error go to errctrl
for each ctrl in me.controls
if ctrl.tabindex=1 then
...
...
errctrl:
msgbox err.number & " " & err.description