0
votes

I am trying to add records from my table into a listbox. Can I use a "For each" statement to add all the records into the listbox?

Ex. Dim rs as recordset

Set rs as CurrentDb.OpenRecordset("CheckTable")

For Each *** in rs!Names

Is that possible? Thanks!

1
Use (a query using) the table as rowsource. No code needed. - Gustav

1 Answers

0
votes

That's how I would populate a listbox (On Form Load)`

For Each QD In CurrentDb.QueryDefs
If QD.Name = "temp" Then CurrentDb.QueryDefs.Delete "temp"
Next
 
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Dim RS As DAO.Recordset
    
SQL = "SELECT   field1  FROM table1  "
Set qdf = CurrentDb.CreateQueryDef("TEMP", SQL)

For Each prm In qdf.Parameters
qdf.Parameters(0) = Forms!form1!List0
Next prm

Set RS = qdf.OpenRecordset
     
     

 Set List0.Recordset = RS