PhoenixofMT
Part-time Access Guru
- Local time
- Today, 12:15
- Joined
- Jul 23, 2008
- Messages
- 35
I have some code that looks something like this:
The problem I have is that if that null check errors out, I get an "Object variable or With block variable not set" error when I hit the rst.Close line in the exit section. This can lead to endless loops.
Is there a way to check that rst is open before I try to close it? I've run into this a couple of times, usually when I comment something out temporarily and it works again when I un-comment it.
In this instance my solution has been to move the null check below the "Set rst =", but I'd like to be able to check it explicitly, rather than be sure my errors will always happen in the right places.
Thanks,
-- Phoenix
Code:
If Nz(some_field, "") then err.Raise 94, etc.
strSQL = "SQL query"
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)
bunch more code...
Exit_MyFunction:
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function
Error_MyFunction
MsgBox err.DESCRIPTION, etc.
Resume Exit_MyFunction
Is there a way to check that rst is open before I try to close it? I've run into this a couple of times, usually when I comment something out temporarily and it works again when I un-comment it.
In this instance my solution has been to move the null check below the "Set rst =", but I'd like to be able to check it explicitly, rather than be sure my errors will always happen in the right places.

Thanks,
-- Phoenix
Last edited: