Does multi-column combo box return variant or fixed type?

R

Rebecca

Hi,

I'm using Access 2000 and I've got a 2 column unbound
combo box that looks up values in a table (first column is
hidden bound column and contains an integer ID number,
second column is displayed and contains the corresponding
text value). I want to ensure that the user chooses a
value before exiting the form.

I tried to evaluate it using the IsNull function:
If IsNull(me.MyComboBox) then
msgbox "Please enter a value"
else
call RoutineThatProcessesData&ClosesForm
End If

I was getting an "invalid use of null" error when the
combo box contained data, but it evaluated correctly when
it was empty. I'm wondering if the data returned by the
combo box is a variant type or if it gets typed according
to the data it looks up. The only info I've been able to
find says that the column property of a combo box returns
a fixed type. I'm not referencing that property, but I
wonder if that still applies.

To add further confusion, I changed my routine so it
employed If not IsNull(me.MyComboBox)then... and it began
to evaluate properly. I have not been able to re-create
the problem, but I'm afraid that it's somehow randomly
occurring and will crop up again.

Any thoughts....

Thanks!
Rebecca
 
N

nath

-----Original Message-----
Hi,

I'm using Access 2000 and I've got a 2 column unbound
combo box that looks up values in a table (first column is
hidden bound column and contains an integer ID number,
second column is displayed and contains the corresponding
text value). I want to ensure that the user chooses a
value before exiting the form.

I tried to evaluate it using the IsNull function:
If IsNull(me.MyComboBox) then
msgbox "Please enter a value"
else
call RoutineThatProcessesData&ClosesForm
End If

I was getting an "invalid use of null" error when the
combo box contained data, but it evaluated correctly when
it was empty. I'm wondering if the data returned by the
combo box is a variant type or if it gets typed according
to the data it looks up. The only info I've been able to
find says that the column property of a combo box returns
a fixed type. I'm not referencing that property, but I
wonder if that still applies.

To add further confusion, I changed my routine so it
employed If not IsNull(me.MyComboBox)then... and it began
to evaluate properly. I have not been able to re-create
the problem, but I'm afraid that it's somehow randomly
occurring and will crop up again.

Any thoughts....

Thanks!
Rebecca
.
try isempty or

if mycombobox.value="" then
msgbox("enter value")
else
end if
 
R

Rebecca

-----Original Message-----


if mycombobox.value="" then
msgbox("enter value")
else
end if

.
Thanks for your suggestions.

Tried IsEmpty, but it evaluated false whether there was
data there or not. Since IsEmpty also requires a variant
type, I think it takes me back to square one.

Tried if mycombobox.value = "" then... and it works if you
set the default value to "", but if the user enters data
and then deletes it, the statement also evaluates
incorrectly.

I guess the fundamental question becomes, what's in a
combo box when no data is entered? Is it a null value, or
an initialized, typed variable with no value, or a zero
length string?

Any ideas?

Thanks!
Rebecca
 
R

Rick Brandt

Rebecca said:
I guess the fundamental question becomes, what's in a
combo box when no data is entered? Is it a null value, or
an initialized, typed variable with no value, or a zero
length string?

It depends on the field it is bound to. If that field allows zero-length strings
then it could be a ZLS or a Null. If the field does not allow ZLS then it will be
Null. Regardless of the field, the value of the ComboBox should be Null when you are
filling out a new record and haven't yet made an entry in the ComboBox (unless the
field or control has a ZLS as the default).

An Unbound ComboBox with no selection should have a value of Null.

You could always try ..

If Len(Me!ComboBoxName & "")=0

That will be true whether the Combo's value is Null or a ZLS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top