Set ControlSource to RecordSet?

E

elicooper

I'm trying to set a listbox's Control Source to an Opened Record Set,
however, I cannot get it to work. Is this possible? Please see the
below code. Thanks!

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("qryClassListByDate")
qdf.Parameters(0) = _
DateSerial(Year(Date), Month(Date), 1)
qdf.Parameters(1) = _
DateSerial(Year(Date), 1 + Month(Date), 0)
Set rst = qdf.OpenRecordset

Me.lstCourses.RowSource = rst
 
M

Marshall Barton

I'm trying to set a listbox's Control Source to an Opened Record Set,
however, I cannot get it to work. Is this possible? Please see the
below code. Thanks!

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("qryClassListByDate")
qdf.Parameters(0) = _
DateSerial(Year(Date), Month(Date), 1)
qdf.Parameters(1) = _
DateSerial(Year(Date), 1 + Month(Date), 0)
Set rst = qdf.OpenRecordset

Me.lstCourses.RowSource = rst


In A2002, you can use:
Me.lstCourses.Recordset = rst

But, in any version, you can set a couple of hidden text
boxex on the form to the dates. Then the query's Where
clause coulf be:
WHERE datefield Between Forms!formname.txt1 And
Forms!formname.txt2

This way, the only code you would need is:
Me.lstCourses.Requery
 

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