ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   setfocus does not work as expected (https://www.excelbanter.com/excel-programming/329513-setfocus-does-not-work-expected.html)

wgoldfarb

setfocus does not work as expected
 
I am new to visual basic for applications and I am trying to create a form
(in Excel 2003, Windows XP pro) that provides an interactive script to fill
out certain cells in an spreadsheet.

Each question (in the form of a label) and space for the answer (textbox or
combobox) becomes visible only after the user has answered the preceeding
question. This is because the next question may change (or be skipped)
depending on the answer to the current question.

For some reason the focus is not following the tab order correctly. As an
example, I have a textbox followed by a combobox. As the user is typing in
the textbox, the combobox remains hidden. Once the user enters the answer,
the exit code for the textbox changes the text of the label for the next
question and sets the visible property of the label and the combobox to true.
The combobox is the next control in the tab order, so I would expect the
focus to go from the textbox to the combobox. Instead, it goes back to the
first control on the form. Once the combobox is visible, however, tabbing
through the controls produces the expected result, so the problem seems to
happen only when the combobox is receiving the focus immediately after
becoming visible. Similar things happen in several places on the form.

I tried using setfocus to 'force' the focus to go to the correct control but
it does not work. I also tried putting the code to change the visible
property of the combobox in the code for the afterupdate event of the
textbox. Nothing worked.

Any ideas?

Any help will be greatly appreciated!

William



All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com