How to read values from a combo box

S

Shiva

Hi,

I'm trying to read and count the values of a combo box (called filetype) on
a subform. The possible values of the combo box depend on a SQL-query
assigned to the rowsource property of the combo box.

Here's a piece of the code:

Dim rs As ADODB.Recordset

Set rs = Form_Subform_films.filetype.Recordset.Clone

If rs.RecordCount = 1 Then
GetSingleAvailableFiletype_id = Str(rs![Id])
End If

rs.Close
Set rs = Nothing

The second command (Set rs = Form..) generates a type mismatch error. What's
wrong?

I'm using Access 2002 so ADO Recordsets should work

Thanks in advance!
 
B

Barry-Jon

If you want to count the items in the combobox you can use the combobox
listcount property. To know what the data is you can use the itemdata
propery. To put it together you could do something like...

Dim i As Long

For i = 0 To Me.cboFileType.ListCount - 1 'ItemData is 0 based
'Print all the possible values in the combobox
Debug.Print Me.cboFileType.ItemData(i)
Next i

Unless I am missing something - no need to use a recordset at all...
 
S

Shiva

Barry-Jon said:
If you want to count the items in the combobox you can use the
combobox listcount property. To know what the data is you can use
the itemdata propery. To put it together you could do something
like...

Dim i As Long

For i = 0 To Me.cboFileType.ListCount - 1 'ItemData is 0 based
'Print all the possible values in the combobox
Debug.Print Me.cboFileType.ItemData(i)
Next i

Unless I am missing something - no need to use a recordset at all...


It's easier than I thought :) Thanks a lot!
 

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