How do you properly open and close a recordset in ado? Currently, this is my overall structure:
I've been doing some research which hasn't been too helpful and find myself a bit confused as to what's the best or most efficient way of doing this. Moreover, I find myself confused about the use of "New". When do I need to use it and why?
Code:
Dim cn As New ADODB.Connection Dim rs As ADODB.Recordset Dim rs2 As ADODB.Recordset cn.Open CurrentProject.Connection Set rs = New ADODB.Recordset rs.Open "table or SELECT...", cn, adOpenDynamic (or blank if forward-only), adLockOptimistic (or blank if read-only) 'If I'm opening more than one recordset which is often the case Set rs2 = New ADODB.Recordset rs2.Open "table or SELECT...", cn, adOpenDynamic (or blank if forward-only), adLockOptimistic (or blank if read-only) 'rest of code rs.Close Set rs = Nothing rs2.Close Set rs2 = Nothing cn.Close
Comment