Set ControlSource to RecordSet?

  • Thread starter Thread starter elicooper
  • Start date Start date
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
 
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
 
Back
Top