Retaining focus on a textbox / listbox item pair after validation = false.

C

chatterbox

Hi Everybody.

I have a wee problem that has evaded my best efforts over the past
couple of days and I hope one of you out there can shine some light for
me.

The problem centres on two form controls. Essentially there is a text
box and a list box. For each entry of the list the user must enter a
conversion rate into the text box. The user clicks a list item then
enters a value into the text box. The user then either clicks another
list item or decides to do something else. My problem begins with
validation of the text box entry. I do not wish to use a textbox_change
event, but rather wait until the user clicks another list item or other
control, before I trigger the validation. If validation is true, no
problems. However, if validation is false, eg. the user entered a word
string, no matter how I code it, using textbox_Exit (with Cancel =
true, or enable = false then true, etc) or other text box event, or a
_listbox event, I am not able to figure out how to both keep focus on
the incorrect text box entry and force the list box to stay on the
offending list item. My best to date has been to keep focus on the
textbox offending entry, but the listbox moves to the new user
selection.

If anybody can shed some light on how I might do this without having to
include a dedicated 'OK' button for each new user entry, I would be
most grateful

Ciao for now.

chatterbox
 
B

Bill Renaud

It looks to me like you should add an "Update" button for the user to click
after they have selected an item in the list, then entered the conversion
rate in the text box. This could be the default button. When the user
presses the return key, validation would be performed, and focus returned to
the text box for editing, if necessary.

Otherwise, if the user simply selects another list item, Excel doesn't know
whether to apply the conversion rate to the previously selected list item.
Maybe nothing should be done, because the user simply selected the wrong
item in the list box.

Good form design usually means that the Cancel button also exits from the
form, just like the OK button, but any changes are cancelled (undone). If
the user selects an item in the list box, enters a conversion rate in the
text box, and then decides to hit the Cancel button, what should happen?
Should all previous changes/entries be undone?
 
C

chatterbox

Bill said:
It looks to me like you should add an "Update" button for the user to click
after they have selected an item in the list, then entered the conversion
rate in the text box. This could be the default button. When the user
presses the return key, validation would be performed, and focus returned to
the text box for editing, if necessary.

Otherwise, if the user simply selects another list item, Excel doesn't know
whether to apply the conversion rate to the previously selected list item.
Maybe nothing should be done, because the user simply selected the wrong
item in the list box.

Good form design usually means that the Cancel button also exits from the
form, just like the OK button, but any changes are cancelled (undone). If
the user selects an item in the list box, enters a conversion rate in the
text box, and then decides to hit the Cancel button, what should happen?
Should all previous changes/entries be undone?

Thanks Bill for the advice.

I started down the road you advised, but then had an all too rare flash
of inspiration. I used the textbox_Exit event to kick off the
validation. If it validated good, no action was taken. If it validated
false it locked the list box, passed a message to the user and set
focus back on the text box. I have included OK and Cancel command
buttons as you suggest.

Thanks again.

chatterbox
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top