My New Year will be a little happier if I can solve the following problem.
I have a form with a combo box to select, from the underlying dataset, a record on which to work. I don't want the user to have an option to enter new list entries, so "Limit to List" is set on. The form also contains a Cancel button to allow the user to reverse any wrong changes and get out. However, if the user enters in the combo box a name that is not in the dataset, Access immediately produces the message "The text you entered isn't an item in the list". There is no way Access will allow me to proceed while the invalid text remains in the box. This occurs even if he clicks the Cancel button, because the "Not in List" event fires before even the MouseDown event of the Cancel button. In fact the order of events includes
combo.NotInList
combo.BeforeUpdate
combo.AfterUpdate
combo.LostFocus
CancelButton.MouseDown
CancelButton.OnClick
meaning that I can find no way of honouring the user's desire to cancel his mistake and get out. He has to think of backspacing over his entry (or using Ctrl-Z, if he is aware of this) and then using the Cancel button. This is rather non-intuitive and seems to defeat the purpose of providing a Cancel button.
The only way I can think of solving the problem is to
- In a combo box "Not in List" event procedure programmatically clear the entered text, set a public flag to remind me that the error occurred, and then tell Access to ignore it (Response=acDataErrContinue);
- In the Before or AfterUpdate event, check the flag and if set, clear it and produce the "Not in List" error message - after temporarily restoring the erroneous text so the user can see what he's done;
- Then return to the combo box to force him to clear or correct it.