Should i rs.close and Set rs = Nothing in each loop?
Hi,
The code below simply creates a fixed-field string from the data in a database.
It reads a list of item codes from another file for the where clause of the query.
Question:
Should I close the recordset and set it to nothing before re-setting the query with the new where clause?
It doesn't seem to matter whether I do or don't.
Thanks,
Al.
Code:
Open "d:\focus\itemcode.prn" For Input As #1
While Not EOF(1)
Line Input #1, ItemCode
Set rs = cn.Execute("Select t$item,t$desc,t$cost,t$whse,t$quan " _
& "from tiitm001 where t$item='" & ItemCode & "'")
Do Until rs.EOF = True
FocusString = Space(80)
Mid(FocusString, 1, 20) = rs.Fields(0).Value
Mid(FocusString, 21, 30) = rs.Fields(1).Value
Mid(FocusString, 51, 10) = rs.Fields(2).Value
Mid(FocusString, 61, 10) = rs.Fields(3).Value
Mid(FocusString, 71, 10) = rs.Fields(4).Value
Print #2, FocusString
rs.MoveNext
Loop
' **************************************
' Do I need the following 2 lines for each iteration of the While/Wend loop?
rs.Close
Set rs = Nothing
' **************************************
Wend
cn.Close
Close #1
Close #2
Set rs = Nothing
Set cn = Nothing