Previously, I had been using this sort of setup to clear out recordset and database objects after using them in code:
Well, then one day I got an error, b/c the recordset object had already been closed/cleared out by an earlier statement, so I thought I would try to adjust it a little to get it to always work without error, and also to get it all to fit on one line... so I changed it to this:
Well, I just got to thinking this morning (I have had an error or two pop up with this in the past, but just fixed the error and went on about my business), and thought: what if the colon doesn't cause things to work the way I was thinking...
If I remember correctly, entering a colon at the end of a line will allow you to run another line immediately after it. So that sounded like the perfect fit here. However, I'm beginning to wonder differently.
In my new method, does it actually run like this:
Or, does it run (as I'm now beginning to think it does) as this:
Thanks in advance for any thoughts or references on this.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
Code:
[green]'Setup variables[/green]
Dim db as DAO.Database
Dim rs as DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("MyTableName")
[green]'Run whatever code here
'
'
'Clean-up objects:[/green]
rs.Close
Set rs = Nothing
db.close
Set db = Nothing
Well, then one day I got an error, b/c the recordset object had already been closed/cleared out by an earlier statement, so I thought I would try to adjust it a little to get it to always work without error, and also to get it all to fit on one line... so I changed it to this:
Code:
If rs Is Nothing Then Else rs.Close: Set rs = Nothing
If db Is Nothing Then Else db.Close: Set db = Nothing
Well, I just got to thinking this morning (I have had an error or two pop up with this in the past, but just fixed the error and went on about my business), and thought: what if the colon doesn't cause things to work the way I was thinking...
If I remember correctly, entering a colon at the end of a line will allow you to run another line immediately after it. So that sounded like the perfect fit here. However, I'm beginning to wonder differently.
In my new method, does it actually run like this:
Code:
If rs Is Nothing Then
Else
rs.Close
[highlight][b] Set rs = Nothing[/b][/highlight]
End If
Or, does it run (as I'm now beginning to think it does) as this:
Code:
If rs Is Nothing Then
Else
rs.Close
End If
[highlight][b]Set rs = Nothing[/b][/highlight]
Thanks in advance for any thoughts or references on this.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57