W
wgoldfarb
I have an interactive form that gathers information from the user. The
questions change depending on the previous answers, so upcoming questions are
hidden until needed.
My problem is the following: on the 'lostfocus' event of each control I have
some code that determines which question should be next depending on the
value of previous controls, and makes it visible. The lost focus event is
typically something like the following:
Private Sub Question019TextBox_lostfocus()
If Me.Question019TextBox.value > 0 Then
Me.Question020Label.Visible = True
Me.Question020TextBox.Visible = True
Else
Me.Question021Label.Visible = True
Me.Question021ComboBox.Visible = True
End If
end sub
For some reason, however, Access does not set the focus to the next control
(controls for questions 20 or 21, in this case), but instead goes back to the
first visible control on the form. All the tab stop indices are correctly set
and the tab stop property is set to true, and still the control does not get
the focus. If I force it with a setfocus command after the '.visible = true'
statement everything works well, but the problem is that I am then unable to
go back to a previous control by using shift-tab (because when the current
control loses the focus due to the shift-tab, the lost focus code is called
and the setfocus command is executed). I guess I could make it work by
putting code in each control's keyup event to determine if tab or shift-tab
were pressed, and then using setfocus accordingly, but this seems "messy" and
complicated. So, is there a way to avoid having to use setfocus in teh code
above, and still have Access set the focus properyl? Why is Access not
setting the focus correctly in the code above?
I tried repainting the form after making the next control visible but it did
not work.
any thoughts or suggestions?
Thanks in advance,
William
questions change depending on the previous answers, so upcoming questions are
hidden until needed.
My problem is the following: on the 'lostfocus' event of each control I have
some code that determines which question should be next depending on the
value of previous controls, and makes it visible. The lost focus event is
typically something like the following:
Private Sub Question019TextBox_lostfocus()
If Me.Question019TextBox.value > 0 Then
Me.Question020Label.Visible = True
Me.Question020TextBox.Visible = True
Else
Me.Question021Label.Visible = True
Me.Question021ComboBox.Visible = True
End If
end sub
For some reason, however, Access does not set the focus to the next control
(controls for questions 20 or 21, in this case), but instead goes back to the
first visible control on the form. All the tab stop indices are correctly set
and the tab stop property is set to true, and still the control does not get
the focus. If I force it with a setfocus command after the '.visible = true'
statement everything works well, but the problem is that I am then unable to
go back to a previous control by using shift-tab (because when the current
control loses the focus due to the shift-tab, the lost focus code is called
and the setfocus command is executed). I guess I could make it work by
putting code in each control's keyup event to determine if tab or shift-tab
were pressed, and then using setfocus accordingly, but this seems "messy" and
complicated. So, is there a way to avoid having to use setfocus in teh code
above, and still have Access set the focus properyl? Why is Access not
setting the focus correctly in the code above?
I tried repainting the form after making the next control visible but it did
not work.
any thoughts or suggestions?
Thanks in advance,
William