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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combobox itemdata returns null 1

Status
Not open for further replies.

jnoody

Programmer
May 14, 2004
19
US
The problem is that whenever I try to use ItemData to pull the value of the index field, it returns null, even if I specify the number of a row from the combobox that I know is a valid argument.

Here's the scenario:

I have a combobox selecting 2 fields from a table as its rowsource. One field is an index and the other is an index field. The bound column is set to the index field.

Here's the code:

Private Sub cboCountry_AfterUpdate()
Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "idsCountryID = " & Me.cboCountry.ItemData(Me.cboCountry)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
rs.Close
Set rs = Nothing
End Sub

When debugging, I can see that Me.cboCountry is evaluating to 0, 1, 2, or 3 depending on what the combobox has selected and Me.cboCountry.ItemData(Me.cboCountry) is evaluating to null even though there is definately data in rows 0, 1, 2, and 3 of the combobox.

Any suggestions? Thanks ahead of time.
 
You can use cboCountry.Value to get the selected itemdata.

-Pete
 
I tried and cboCountry.value returns the same thing as ListIndex, not the actual data in the records pulled from the row source. What I need is a way to get the actual data. For example, My combobox has four country names in it each with an ID. I need code that will pull those values.

Does anyone have the answer?
 
Sorry. Turns out that I had my Bound Column set to 0 instead of 1. cboCountry.value works perfectly. Thanks, Pete!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top