D
Deleted member 73419
Guest
Hi all,
I have a form with a listbox on and want to bind it to a recordset. So far I have this:
The idea being when the form is opened, the recordset fills the listbox however it doesn't. The problem is the recordset and database are closed at the and of the sub. If I comment out the last four lines everything works and the listbox is populated.
I want to do a proper job at this so if I leave these lines out, how to I clean up the variables since I can only use them within that particular sub? It's not like I can close the database and set it to nothing from another routine as I won't be able to access them.
Where am I going wrong?
Thanks
I have a form with a listbox on and want to bind it to a recordset. So far I have this:
Code:
Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strCustomersSQL As String
strCustomersSQL = "SELECT a,b,c FROM d;"
Set db = CurrentDb
Set rs = db.OpenRecordset(strCustomersSQL, , dbReadOnly)
rs.MoveFirst
Set lstCustomer.Recordset = rs
lstCustomer.Requery
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
The idea being when the form is opened, the recordset fills the listbox however it doesn't. The problem is the recordset and database are closed at the and of the sub. If I comment out the last four lines everything works and the listbox is populated.
I want to do a proper job at this so if I leave these lines out, how to I clean up the variables since I can only use them within that particular sub? It's not like I can close the database and set it to nothing from another routine as I won't be able to access them.
Where am I going wrong?
Thanks