combo box - Help!

L

lendapilot

Only one row will be selected from a combo box. I need the 3rd value in the
row.

Is there a simpler way then using the for-next loop? Is ItemsSelected and
ItemData the only way to do this?

I'm looking to extract records between a date range for a specific payee.

Payto is the combo box. Here's how I'm doing it now. Thanks.

Private Sub db_betw_dates_obj_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim payto As Control, varItm As Variant

For Each varItm In payto.ItemsSelected

strSQL = "SELECT * FROM RONCHECK_access " _
& "WHERE (((RONCHECK_access.DATE) Between " _
& Format(start_date_cal.Value, "\#mm\/dd\/yyyy\#") & " And " & Format
(end_date_cal.Value, "\#mm\/dd\/yyyy\#") & " And RONCHECK_access.PAYEE =
payto.ItemData(varItm));"

Next varItm


Me.db_betw_dates_obj.RowSource = strSQL


'Set rs = db.OpenRecordset(strSQL)
End Sub
 
G

George Nicholson

If the value you want is what is showing in the combobox then simply
reference the combobox:
...RONCHECK_access.PAYEE = payto

If you want the value from a different column use
...RONCHECK_access.PAYEE = payto.Column(2)
That should give you the 3rd column, since 1st column = column(0)

There is usually no need to use ItemsSelected or a ForEach loop unless you
have a multi-select listbox with more than one item selected.

Remember that comboboxes return Null if there is no current selection and
plan accordingly.
 
L

lendapilot

Thatworked! Thanks. It's amazing how the simple things escape us from all the
books.
 

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