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 value not consistent

Status
Not open for further replies.

ngreenleaf

Programmer
Jan 13, 2003
24
US
I have a combo box -- call it Combo1. If I backspace over the text in the box until there is nothing and hit Enter the Click event procedure correctly sees Combo1.Value as set to "" (nothing). However, if I do the same and then change focus to another control then Combo1.Value is sometimes "" and sometimes it is the text that was there before I did the backspacing. It depends on which control I change focus to and seems to be very consistent.

I tried the same thing using the Exit event instead of Click and got similar results. Am I using the wrong event? What I want to do is check the contents of the text part of the combo box and do different things accordingly. First, I need to know if this value is <> &quot;&quot; -- actions differ for a &quot;&quot; value and within the &quot;&quot; value as well. I am also tracking the last key typed in the combo box using the Keydown event -- my decisions on what to do depend upon both the contents of the combo box and the last key the user typed.
 
Good afternoon (or morning, or evening) ...

Try using the IsNull function in conjunction with the &quot;&quot; check, something like the following:

If IsNull(MyText) Or MyText = &quot;&quot; Then
' do something
Else
' do something else
End If

A Null value (IsNull) is not the same as an empty value (&quot;&quot;); this may be why you're getting funky data.

HTH

Greg
If you don't understand, just nod and smile ...
 
when I use MsgBox to show the value to me sometimes it is NULL or empty and sometimes it is the actual value that was removed from the combo box.

Example:

(1) combo box has the value &quot;abc&quot;
(2) I backspace over the &quot;abc&quot; so that the combo box is showing &quot;&quot;
(3) I hit enter - and my msgbox has the value &quot;&quot;
(4) repeat steps 1 and 2
(5) I move focus to a different control (a text box or a command button) - and my msgbox displays &quot;abc&quot;.

(note the quotes are used for effect - they are obviously not displayed in the combo box)

Clearly if the value displayed in my combo box is &quot;abc&quot; it cannot be NULL or &quot;&quot;.

The question... if I backspace over the text in the combo box and then move focus -- why is the value in my combo box still set to the value before I backspaced? The same thing happens with the delete key.

Thanks in advance for any additional help.
 
Any After_Update or Before_Update events specified for the combo box?

If you don't understand, just nod and smile ...
 
This combo box has the following event procedures:

1) KeyDown -- I track the last key to see if the user has entered characters or deleted/backspaced them

2) NotInList -- just gives an error message

3) DblClick -- double clicking on a publisher name in the combo box pops up a form with the publisher information and the user can edit this information and the table will be updated.

4) Exit -- this is very complicated. I have publisher names in the list box. I have added one row bound to a NULL value. So the combo box has NULL (displays to the user as &quot;New...&quot;) and a list of publisher names. If the user selects or types a valid publisher name then I update the table with the new publisher name. If the user clicks &quot;New...&quot; I open a new form to enter publisher information. If the user backspaces or deletes the publisher name I want update the table with a NULL publisher name. I tell the difference between clicking on New... (bound to NULL) and deleting the field in the text box based on the last key recorded by the KeyDown event.

In the Exit procedure I have just added a MsgBox at the top to see what it thinks the combobox Value is. It is always fine if the user deletes the text and then presses Enter. But if the user backspaces or deletes the text and then changes focus the original text is often still the value I get.

I tried using Click instead of Exit, and I tried using AfterUpdate... same results. It seems to depend upon which control I change focus to... but I cannot say I have clearly identified a pattern yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top