Listindex value returned improperly...?

  • Thread starter Thread starter Randall Arnold
  • Start date Start date
R

Randall Arnold

I have a weird one. I have an Address List control (on main form) that
pulls up a list of street addresses and job numbers (column 0 and 1, resp)
from a table. Toggle buttons below the list pull up either a scheduling
form or an editing form in a subform depending on value. By default
everything loads just fine. However, if the first address is selected when
the main form loads (schedule mode), and I then click to edit mode, I get a
syntax error in my VB code that is designed to cause the edit subform to
jump to the selected record (in this case the first, or default, address).
Debugging showed me that the Listindex property is reported as -1 when it
should be 0. In fact, VB Help indicates 0 is the starting ordinal! There
should be no -1 value.

Note that this error does not come up if I select another address prior to
changing subforms... even if I move back to the original default record that
caused the error!

I have the column heads selected; does that affect the listindex? And if
so, why does the Listindex return the proper default value (0) when the main
form and default subform load, but the wrong value (-1) when I load a new
subform? Makes no sense.

Randall Arnold
 
Randall said:
I have a weird one. I have an Address List control (on main form) that
pulls up a list of street addresses and job numbers (column 0 and 1, resp)
from a table. Toggle buttons below the list pull up either a scheduling
form or an editing form in a subform depending on value. By default
everything loads just fine. However, if the first address is selected when
the main form loads (schedule mode), and I then click to edit mode, I get a
syntax error in my VB code that is designed to cause the edit subform to
jump to the selected record (in this case the first, or default, address).
Debugging showed me that the Listindex property is reported as -1 when it
should be 0. In fact, VB Help indicates 0 is the starting ordinal! There
should be no -1 value.

Note that this error does not come up if I select another address prior to
changing subforms... even if I move back to the original default record that
caused the error!

I have the column heads selected; does that affect the listindex? And if
so, why does the Listindex return the proper default value (0) when the main
form and default subform load, but the wrong value (-1) when I load a new
subform?


I don't see how displaying a subform would have anything to
do with the combobox. However, I may be able to clarify a
couple of things.

ListIndex = -1 means that the combo's Value property is not
one of the values in the RowSource's bound column. (It can
also be used as a way of checking if the value is not in the
list.)

This implies(?) that you have somehow assigned something to
either the combo's Value (or maybe DefaultValue) property
that is not in the list.

It's probably irrelevant to your problem, but if ColumnHeads
is Yes, then Column(N, 0) refers to the Nth column heading,
not the first row of data.
 
Here's the situation:

When the main form comes up, I have code that selects the first item in the
list control. If I examine the Listindex at that point, its value is 0.
After I change the form in the subform, however, the Listindex value is
now -1. During this transaction I perform zero operations on the list
control. I see no relationship, either (thus why I called it weird) but
that's what's happening.

I should have stated that the control is unbound, and populated by SQL. I
*assumed* the bound column wouldn't be a factor in such a case... am I
wrong?

Your comment about the ColumnHead appears to explain part of the problem,
but not why Listindex value is 0 when I initially select the first item with
code, and then -1 (as crazy as it sounds) when the subform changes.

Anyway, I inserted a workaround that tells Access if the value is -1 then
it's really 0, and everything works. But I still don't get it!

Thanks,

Randall Arnold
 
Randall said:
Here's the situation:

When the main form comes up, I have code that selects the first item in the
list control. If I examine the Listindex at that point, its value is 0.
After I change the form in the subform, however, the Listindex value is
now -1. During this transaction I perform zero operations on the list
control. I see no relationship, either (thus why I called it weird) but
that's what's happening.

I should have stated that the control is unbound, and populated by SQL. I
*assumed* the bound column wouldn't be a factor in such a case... am I
wrong?

The BoundColumn is the one that supplies the combo's Value
property (it has nothing to do with whether or not the
control is bound to a field in the form's record source).
This can make a big difference when you use code to assign a
value to the combo box. If the BoundColumn is different
from the first non-zero ColumnWidth column, you can not set
the Value property to same string that would be displayed in
the combo's display box.

Your comment about the ColumnHead appears to explain part of the problem,
but not why Listindex value is 0 when I initially select the first item with
code, and then -1 (as crazy as it sounds) when the subform changes.

Anyway, I inserted a workaround that tells Access if the value is -1 then
it's really 0, and everything works. But I still don't get it!

I don't get it either, but, like I said earlier, I've never
heard of this kind of problem and still suspect there just
may be something in your code. I'm going to be tied up most
of this weekend, but if you'll post the related code, I'd
like to look at it to see if I can spot anything.
--
Marsh
MVP [MS Access]



 
Thanks, Marshall, but I can assure you there's no code that should be
changing this value (at least none I've written). I've gone over this with
a fine-toothed comb and even commented out sections to troubleshoot-- value
still reported incorrectly. As for the Bound Column, it's set to 1.

I'm currently cleaning up the code on this project but if I don't figure it
our afterward I'll post what I have.

It gets even weirder, though-- I have a need for the same list to have
Multiselect set to None (0) on some cases and Extended (2) in others. When
I try to set the value programmatically, however, I get an error from Access
stating "You can't assign a value to this object" (error 2448). Access Help
insists that the property is read/write--???

This is nuts...

Randall Arnold

Marshall Barton said:
Randall said:
Here's the situation:

When the main form comes up, I have code that selects the first item in the
list control. If I examine the Listindex at that point, its value is 0.
After I change the form in the subform, however, the Listindex value is
now -1. During this transaction I perform zero operations on the list
control. I see no relationship, either (thus why I called it weird) but
that's what's happening.

I should have stated that the control is unbound, and populated by SQL. I
*assumed* the bound column wouldn't be a factor in such a case... am I
wrong?

The BoundColumn is the one that supplies the combo's Value
property (it has nothing to do with whether or not the
control is bound to a field in the form's record source).
This can make a big difference when you use code to assign a
value to the combo box. If the BoundColumn is different
from the first non-zero ColumnWidth column, you can not set
the Value property to same string that would be displayed in
the combo's display box.

Your comment about the ColumnHead appears to explain part of the problem,
but not why Listindex value is 0 when I initially select the first item with
code, and then -1 (as crazy as it sounds) when the subform changes.

Anyway, I inserted a workaround that tells Access if the value is -1 then
it's really 0, and everything works. But I still don't get it!

I don't get it either, but, like I said earlier, I've never
heard of this kind of problem and still suspect there just
may be something in your code. I'm going to be tied up most
of this weekend, but if you'll post the related code, I'd
like to look at it to see if I can spot anything.
--
Marsh
MVP [MS Access]



get
a prior
to record
that the
main
 
Randall said:
Thanks, Marshall, but I can assure you there's no code that should be
changing this value (at least none I've written). I've gone over this with
a fine-toothed comb and even commented out sections to troubleshoot-- value
still reported incorrectly. As for the Bound Column, it's set to 1.

I'm currently cleaning up the code on this project but if I don't figure it
our afterward I'll post what I have.

It gets even weirder, though-- I have a need for the same list to have
Multiselect set to None (0) on some cases and Extended (2) in others. When
I try to set the value programmatically, however, I get an error from Access
stating "You can't assign a value to this object" (error 2448). Access Help
insists that the property is read/write--???


I thought we were talking about a combo box, not a list box.
I hope that hasn't caused any confusion. Because of their
limited formatting capabilities, I've never used a List Box
in a real application and use a continuous subform instead.
OTOH, a single select list box's properties are nearly
identical to a combo box, so I don't think I've stuck my
foot in my mouth.

Regardless of all that, you definitely need to be aware that
multiselect list boxes do not have a value property. How
could they, they have multiple values which you have to loop
through their ItemsSelected collection in order to retrieve.
--
Marsh
MVP [MS Access]



 
Back
Top