I have a function "ReturnDocument Rules" that returns a recordset. Everything works if I do not close the recordset and set it to nothing, but I know this is bad programming practice. If I do close the recordset and set it to nothing, obviously after I have set the function to the recordset, return value is still set to nothing.
My code:
How can I return this recordset and still properly close it in the function?
My code:
Code:
Public Function ReturnDocumentRules() As Recordset 'Open DB and retrieve rules from Rules table that apply to selected document Dim db As Database, rs As Recordset Set db = OpenDatabase("H:\9000\9000.mdb") Set rs = db.OpenRecordset("SELECT rule FROM Rules WHERE docID=" & frm_mainMenu.cb_DocType.Value _ & " ORDER BY docID", dbOpenSnapshot) Set ReturnDocumentRules = rs rs.Close db.Close Set rs = Nothing Set db = Nothing End Function
Comment