Combo box and null values

  • Thread starter Thread starter Zippy the Pinhead
  • Start date Start date
Z

Zippy the Pinhead

I have a form with a subform. On the subform, the user selects from a
list of items using a combo box.

THe subform is based on a query which is based on a details table.
The primary key from the main form's table and the primary key of a
table from which the row source for the combo box comes make up the
multi-field primary key for a two-field detail table. THe combo box's
"limit to list" property is true.

So far so good. But when a user mistakenly selects from the list and
tries to backspace over the entry, or in any other manner to undo the
addition to mistaken addition to what will become the entry in the
detail table, the thing falls apart with an error message about
attempting to place a null value into a primary field key.

How can I enable the user to undo a mistaken selection from a combo
box without triggering the error message and ultimately exiting
without saving the data entered into that instance of the form?

Thanks in advance.
 
Zippy the Pinhead said:
I have a form with a subform. On the subform, the user selects from a
list of items using a combo box.

THe subform is based on a query which is based on a details table.
The primary key from the main form's table and the primary key of a
table from which the row source for the combo box comes make up the
multi-field primary key for a two-field detail table. THe combo box's
"limit to list" property is true.

So far so good. But when a user mistakenly selects from the list and
tries to backspace over the entry, or in any other manner to undo the
addition to mistaken addition to what will become the entry in the
detail table, the thing falls apart with an error message about
attempting to place a null value into a primary field key.

How can I enable the user to undo a mistaken selection from a combo
box without triggering the error message and ultimately exiting
without saving the data entered into that instance of the form?

Thanks in advance.

Normally pressing the Escape key will undo the changes to the control,
and a second press will undo all changes to the current record. Does
that not work for some reason?
 
Normally pressing the Escape key will undo the changes to the control,
and a second press will undo all changes to the current record. Does
that not work for some reason?

THe problem occurs when the user backspaces over the text in the
dropdown box in an effort to undo the entry INSTEAD of using the <esc>
key. Maybe I need to trap that keypress? Or can I make that column
of the combo-box "not enabled" because input is limited to the list
anyway?

Thanks.
 
Zippy the Pinhead said:
THe problem occurs when the user backspaces over the text in the
dropdown box in an effort to undo the entry INSTEAD of using the <esc>
key. Maybe I need to trap that keypress? Or can I make that column
of the combo-box "not enabled" because input is limited to the list
anyway?

Hmm. Educating your users is probably the best solution, but I suppose
you might try something like this for the combo box's Change event:

Private Sub cboMyCombo_Change()

With Me.cboMyCombo
If Len(.Text) = 0 Then
.Undo
End If
End With

End Sub

I'm not sure whether that would be even more confusing or not. The idea
would be that if the user has deleted (by backspacing) all the displayed
text, they must be intending to "reset" the combo to its original value.
 
Hmm. Educating your users is probably the best solution, but I suppose
you might try something like this for the combo box's Change event:

Educate, then put in a "Plan B". That would probably be the best
approach.

Thanks, Dirk
 
Back
Top