Combo Box Error

ray_charles

Registered User.
Local time
Today, 19:06
Joined
Aug 5, 2002
Messages
18
Hello: I have a combo box that displays employee
names, and stores a employeeID in a Orders
table. It works correctly UNTIL . . . I press <spacebar>
and attempt to leave the field either by TAB or ENTER
or whatever. Then I get the following error Msg:

"You tried to assign the Null value to a variable that is
not a variant type"

Then the leave field event is canceled.

Ok. I know how to check the field before attempting to
leave it by using the IsNull function, but, when one or
more spaces are entered, the IsNull function no longer
works and the above error message is generated.

Could this have something to do with the employeeID
being a number?

Also . . . if I attempt to assign a default combo box value
like "(Enter Employee)" via the control default value
property, the default value does not appear.

If anybody can give me a work-around, or, a solution
to my combo box problem, I will nominate them for the
coveted "Ray's Hero" Trophey award :-)

Thanks for any and all input . . . Ray . . .
 
Sorry for a stupid question, but why are you pressing the space bar?

Is your combo box set to limit response to the listed items? I'm guessing not.

I'm thinking that when you add a space or enter any value that is not in your item list, the combo box is trying to store a null value in your table because these items don't have a code associated with them.
 
Well, I guess it is just my mentality that if a user can do it, . . .
someone will do it :-)

I suppose that I could leave this alone, and say if you press
a space or series of spaces without some entry of characters
of any kind you will get this somewhat cryptic message, and,
make them feel like idiots, but I would rather handle it and
never have to deal with the situation.

Yes, I have limit to list items turned on, but, this happens
before that check happens.
 
Hello

You could try the on keypress event of the combobox. This will tell you which key (in ascii code) has been pressed so you can handle them i.e set it to null or another value.

Chris
 
Thanks for your help, here is what I discovered:

A combobox.Value that is connected to a number is a number.
A combo box.Text = the text value being entered in it.

So . . . I took your advice concerning keydown events and
intercepted all spaces, then if the len(trim(combobox.Text))
= 0, then docmd.cancelevent.

Also, if IsNull(combobox.value) (which I never thought
a number could be) then I don't allow the user to leave
the combobox until he enters a value. Notinlist only works
when a user enters something.

Whew ! ! ! That was like pulling teeth, painfull but informative.

Thanx again . . . . Ray . . .
 

Users who are viewing this thread

Back
Top Bottom