User deletes entry from combo box

  • Thread starter Thread starter Curt Gough
  • Start date Start date
C

Curt Gough

I have a combo box on a subform with a query rowsource. The rowsource
includes an ID field and a Name field. The control source of the box is the
ID field in an underlying table. Users select a name using the combo box.
There are instances when the user tries to delete the entry by deleting the
selection in the box. This brings up an error that states "You tried to
assign the Null value to a variable that is not a Variant type". I have
instructed the users to not delete that way and have showed them the proper
way. However, I would like to trap for the error just in case they do try to
use that method. I have placed code in the NotInList, AfterUpdate,
BeforeUpdate events that if the combo box is Null display a message. But
none work. Does anyone have a suggestion as to how that error can be
trapped?

Thanks.
 
Have you considered trying to trap the error in the combo's
Exit eventhandler. There you can also set Cancel so as to
prevent the focus being moved off the combo until the error
is corrected.

Hope This Helps
Gerald Stanley MCSD
 
Perhaps the Form BeforeUpdate event can be used. At that point validate all
fields and if any fail cancel the update.

While other ways to delete data in the field would have to be coded (such as
Control X, space bar, back space, ) you can trap the DeleteKey in the
KeyDown event. Something like... (this is typed rather than copied so
there may be typos and is probably not complete)

Private Sub cboStopThat_Keydown(KeyCode as Integer, Shift as Integer)
If KeyCode = VbKeyDelete then
KeyCode = 0
End If
End Sub
 
Back
Top