Trying to Escape

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I have a form that selects customer records from a table
of 20,000 names. I use a combo box to select the customer
records. I have written in previously about another error
and me.undo helps the previous error, but the user is
getting a different error now. If the user types in a
customer name that doesn't match any records in the combo
box the user needs to click another button (CmdAdd) to
open another form to get the customer data. If the user
doesn't clear out the combo box by hitting the escape
button and clicks CmdAdd the user gets the following error
message: "The text you entered isn't an item in the list,
Select an item from the list, or enter test that matches
one of the listed items." There is no way to write code
for CmdAdd because the error message comes up before any
code is executed in CmdAdd. Is there code I could write
for the combo box to execute when it loses focus to clear
itself out if no item from the list has been selected. Or,
any other suggestions?

Thank you.
 
One approach would be to do away with the CmdAdd button by handling the
creation of new customers in the combo's NotInList eventHandler. The code
for the event would look something like

If MsgBox("Do You Wish to set up a new Customer", vbYesNo) = vbYes Then
DoCmd.OpenForm "frmCustomer", , , , , acDialog, cmbCustomer.Value
Response = acDataErrAdded
Else
cmbCustomer.Undo
Response = acDataErrContinue
End If

Note that the value of the comboBox is passed to the form in the OpenArgs
parameter so that it can be preset into the appropriate text box without the
user having to retype it.

Hope This Helps
Gerald Stanley MCSD
 
Is there code I could write
for the combo box to execute when it loses focus to clear
itself out if no item from the list has been selected. Or,
any other suggestions?

Yes: use the Combo Box's NotInList event to open the form, rather than
putting the code in a command button.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top