stumped on itemdata

kbreiss

Registered User.
Local time
Today, 20:56
Joined
Oct 1, 2002
Messages
228
I'm trying to test the itemdata function but having no luck...

I have a combo box ("cboSiteManagers") that contains ID, Fname, Lname

I've tried the following code
msgbox cboSiteManagers.itemdata(3)

But I get an error that says "Invalid Use of Null"...there are around a hundered entries in this dropdown so I don't understand why it would say null.

I'm looking to try to find an answer why my msgbox doesn't show info row rowindex number 3

Thanks in advance,,
Early I accidentally wrote this post as a reply rather than a new thread...sorry

Kacy
________
Fix ps3
 
Last edited:
I've tried the following code
msgbox cboSiteManagers.itemdata(3)

Where, in an event, which one?
What is it exactly you're trying to achieve?

RV
 
its in an afterupdate event of a combo box....ideally depending on what they choose from this combo box it will run a query and default another combo box to a particular value based on the first combo box

But for now I'm just trying to get a msgbox to display the info of a particular record in a combo box based on the itemdata.
________
Box vaporizers
 
Last edited:
Maybe try Me.cboSiteManagers.Requery just before your MsgBox.
 
KB,

The indexes start at 0. Element number 3 is cboSiteManagers.itemdata(2)
or cboSiteManagers.Column(2)

Wayne
 
Correct me if I'm wrong Wayne but I believe .ItemData(RowIndex) returns the bound column value from a row and the OP said there were around a hundred rows of data. My guess was there were no rows, or less than 4 at any rate, when the code ran hence the Null return.
 
It shows Invalid Use of Null message when there is nothing to show.

Are you sure your combo box has records in it? Are you having that msgbox statement in your Form_Load or Form_Open or button_Click? How do you pull the data and put in the combo box?
 
I've been trying to think of a better way to explain what I'm trying to do...basically when 1 combo box is selected i want another combo box to default to a certain value. Below is the code i'm trying...I'm using 173 to test with...normally this would be a variable.

I'm wanting to default on a record in the combo box...

Dim i As Integer
i = 0
For i = 0 To cboSiteManager.ListCount - 1
If cboSiteManager.Column(0, i) = "173" Then
cboSiteManager.Requery
cboSiteManager.DefaultValue = cboSiteManager.ItemData(i)
End If
Next i
________
SIDE EFFECTS OF NEXIUM
 
Last edited:
Working IF...

I got it to work if I changed the bound column to 1 instead of 0...However it should be 0. If I try to change the "Limit to List" property when the bound column is 0 I get this message....Microsoft Access can't set the LimitToList property to No right now. The first visible column, which is determined by the ColumnsWidth property, isn't equal to the bound column. Adjust the columnWidths property first, and then set the LimitToList property.

When I change the bound column to 1 the code works fine...If I leave it at zero(which it should be ) I get the Null message on the itemdata line of code.

I'm stumped....
________
Lovely Wendie
 
Last edited:
the itemdata line of code returns null when the bound column property of the cbo box is 0. It returns data when the bound column property is set to 1...However I need it set to 0...

any ideas


Dim i As Integer
i = 0
For i = 0 To cboSiteManager.ListCount - 1
If cboSiteManager.Column(0, i) = "173" Then
cboSiteManager.Requery
cboSiteManager.DefaultValue = cboSiteManager.ItemData(i)
End If
Next i
________
Chevrolet Orlando Specifications
 
Last edited:
Got it figured out

for anyone that cares...it was throwing a fit b/c my recordsource of the cboSiteManagers did a concat on two fields..(...id, fname & lname). It didn't like that my column width property was only "0";"1" instead of "0", "1", "1"...
________
Fix ps3
 
Last edited:
Please Explain

I have the bound column property of my combo box set to 0. However in my code before I run it I have to set the bound column to 1...otherwise the itemdata returns null. When the record is saved it does use the 0 bound column.

I'm wondering why would I have to set the bound column to 1 in order to get the itemdata to return data and not null?

i = 0
cboSiteManager.BoundColumn = 1
For i = 0 To cboSiteManager.ListCount - 1
If cboSiteManager.Column(0, i) = CStr(rs!location_contactid_sitemanager) Then
cboSiteManager = cboSiteManager.ItemData(i)
Exit For
End If
Next i
________
FREE WALMART GIFT CARDS
 
Last edited:
I believe you are simply mixing up two "mixed up" descriptions. Yes the index values are zero based but the bound column does *not* use an index value. The bound column references the actual column so the 1st column will be column 1 but you reference it using an index so to retrieve the data requires Me.ComboBoxName.Column(0). I hope that makes some kind of sense to you.
 
Makes Sense

The bound column references the actual column so the 1st column will be column 1
In the combox property though the bound column property is 0...that is what Access defaulted it to when I created the combox....It bounds the FieldID that is invisible.
________
Herbal Shop
 
Last edited:
kbreiss said:
In the combox property though the bound column property is 0...that is what Access defaulted it to when I created the combox....It bounds the FieldID that is invisible.
Setting the bound column to zero does not bind to any data in the combobox - rather it binds it to the list index.

Online help:

BoundColumn Property
When you make a selection from a list box or combo box, the BoundColumn property tells Microsoft Access which column's values to use as the value of the control. If the control is bound to a field, the value in the column specified by the BoundColumn property is stored in the field named in the ControlSource property. Read/write Long.

expression.BoundColumn

expression Required. An expression that returns one of the objects in the Applies To list.

Setting
The BoundColumn property uses the following settings.

Setting Description
0 The ListIndex property value, rather than the column value, is stored in the current record. The ListIndex property value of the first row is 0, the second row is 1, and so on. Microsoft Access sets the ListIndex property when an item is selected from a list box or the list box portion of a combo box. Setting the BoundColumn property to 0 and using the ListIndex property value of the control might be useful if, for example, you are only interested in storing a sequence of numbers.
1 or greater (Default is 1) The value in the specified column becomes the control's value. If the control is bound to a field, then this setting is stored in that field in the current record. The BoundColumn property can't be set to a value larger than the setting of the ColumnCount property.
 
Thanks Tom,
Certainly worth reviewing from time to time.
 
Thanks,

I think I have a pretty good understanding know thanks to all the posts...Thanks to everyone.
________
Homemade vaporizer
 
Last edited:

Users who are viewing this thread

Back
Top Bottom