I have a form with a combo box that I populate with records from a access db (I use linked tables). What I'd like to do is store the records in an instance of a class throughout the life of the program rather than querying the table each time the user selects the combo box. Right now I'm calling a funtion from a private sub, the function returns the DAO recordset data which is what I want but the question I have is, how do I pass the data from the function recordset to a public DAO.Recordset, assuming if this was possible it would hold the recordset data throughout the life of the running program. When I run the code and it finishes Public Rs() in the Watch output window says; Recordset(0 to -1) and No Variables, I'm not sure how to correct this.
Here's my code:
Private Sub cmdGetRecordset_Click()
Dim strDescription As String
Dim strModel As String
Dim rst As DAO.Recordset
Set rst = getdevices()
Do While Not rst.EOF
strDescripton = rst!DESC
strModel = rst!MODEL
Debug.Print strDescription & " " & strModel
rst.MoveNext
Loop
'rst.Close'
'Set rst = Nothing'
End Sub
''''''
Option Compare Database
Public Rs() As DAO.Recordset
Function getdevices() As DAO.Recordset
Dim Rs As Object
Dim CurDatabase As Object
connectDatabase
Set CurDatabase = CurrentDb
Set Rs = CurDatabase.OpenRecordset("SELECT * FROM tblCDA")
Set getdevices = Rs
closeDatabase
End Function