Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box null entry

Status
Not open for further replies.

ngreenleaf

Programmer
Jan 13, 2003
24
US
In a combo box is there a way to distinguish between a user typing in a null value and pressing enter, versus clicking on a list entry that is bound to a NULL value? I thought the ENTER versus CLICK events would distinguish these -- but apparently not.

Details: I have a combo box for a list of names -- a key value and a string value. The only value that can never occur in the list is NULL as it si a primary key. My combo box allows the user to select a name - or select a list item hardwired to the text "New. . .". But the "New. . ." list entry is bound to a NULL whereas the other list entries are bound to their name. It is valid for the user to choose no name. To do this the user must type a NULL (eg delete the characters on the line and press ENTER). It is initially set to NULL - so no selection works fine when creating the record... but if the user is updating an existing record this situation arises. I want to do one thing when the user clicks on "New. . ." and another thing when the user deletes the existing name.

I know one way (I think) - I can put an autonumber on the table and use it as the bound column... then I can use -1 (an invalid value for an autonumber) to bind to "New. . .". In this way NULL will be NULL and "New. . ." will be -1. I do not want to go this route if I do not have to. The name is a good natural key.

One other thought is to work with the keypress event -- this seems almost impossible -- to tell if the user pressed a key, then clicked something abandoning the typing... not sure if this route will work though. Ultimately I need to know if the action that got me to the procedure was pressing ENTER or clicking the mouse.
 
I'm not sure I totally follow your question, but what jumps out at me is that I don't believe the user can type a 'Null'. Typing characters and then deleting them causes Access to put 'nothing' in the field . . . but this is not the same as a Null.

I'm thinking that the only way a 'contaminated' field can become Null is through code, but I'm not sure how you would do that. - - - -

Bryan
 
A user can definitely "type" a NULL. The text box part of the combo comes up populated with the current value of the field in the database. The user backspaces over that field and hits enter. Or if the text part of the combo is already empty and the user positions on the box and simply hits enter... in either case the "value" of the combo box will be null. My terminology is odd - cause they are not "typing" it per se... they are deleting it.

Here's an Example of what I am doing...

column1 column 2
(bound column) value displayed to user
--------------------- -----------------
null New...
abc abc
def def
ghi ghi

If the user clicks on the New... row in the combo list - the Value in the combo box is Null. If the user clicks on any other item in the combo list the Value of the combo box is what was displayed.

If the user types something in the text part of the combo there are three cases:

1) it is an item not in the list -- I can handle it with the NotInList event

2) it is an item in the list and not NULL -- all is well with the world as this is the same as clicking on the item

3) they enter a NULL -- this has the same effect as clicking on "New...". I want a click on new to open a new form, and typing null to set the value in the database to null.

Unfortunately there are no invalid text strings -- or I would bind the New... selection to some invalid string.

Ideas anyone???
 
Solution...

track the last keystroke with the keydown event (don't know exactly why but keypress doesn't work). When retrieving the value from the combo box... if the value is null test to see if the last keystroke was ENTER. If it was ENTER then the user put nothing in the text box and hit enter... otherwise the user clicked the "New..." entry in the listbox. You must also reset the last keystroke to anything other than ENTER after processing completes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top