Form_Close: Recordset Out Of Scope?

  • Thread starter (PeteCresswell)
  • Start date
P

(PeteCresswell)

In Form_Open, I'm creating a recordset.

That recordset is used successfully in various event functions
while the form is open.

In Form_Close, however, it seems like it does not exist when I go
to Close/Nothing it.

viz:
-------------------------------------------------------------------
Private Sub Form_Close()
debugStackPush Me.Name & ": Form_Close"
On Error GoTo Form_Close_err

' PURPOSE: - To clean up after ourselves table-wise
' - To save form's location so we can restore it next
' time

' Trapping out w/"3420: Object invalid or no longer set."

mIndexTableRS.Close
Set mIndexTableRS = Nothing

FormDimensions_Save Me, CurrentUserGet()

Form_Close_xit:
DebugStackPop
On Error Resume Next
Exit Sub

Form_Close_err:
BugAlert True, ""
Resume Form_Close_xit
End Sub
-------------------------------------------------------------------
 
A

Arvin Meyer [MVP]

Try closing the recordset in the error handler using a Case statement or If
.... Then construct to check for the existence of the recordset. If the
recordset has not been instantiated, you will always get an error.
 
P

(PeteCresswell)

Per Arvin Meyer [MVP]:
Try closing the recordset in the error handler using a Case statement or If
... Then construct to check for the existence of the recordset. If the
recordset has not been instantiated, you will always get an error.

No problem there.

If nothing else, I'll just wrap it in On Error Resume Next...

But what I'm wondering is whether it's even supposed tb there by
the time Form_Close fires.

I haven't done anything explicit (I hope....{fingers crossed..})
to close it.... yet it seems tb closed.

From context so far, I'd guess that it's not expected tb closed.
 
B

boblarson

Since the Close event is the last event, the recordset has already been
eliminated in the Unload event. You should use the form's UNLOAD event if
you want to do manipulation of the recordset before closing the form.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________
 
P

(PeteCresswell)

Per boblarson:
Since the Close event is the last event, the recordset has already been
eliminated in the Unload event. You should use the form's UNLOAD event if
you want to do manipulation of the recordset before closing the form.

I found the problem.

In Form_Open() (where I set the pointer to the RS - which was
opened as "table"), I set a pointer to the work db where the
table lives and then did a .OpenRecordset("whatever",
dbOpenTable) against "WorkDB".

At the end of Form_Open() I dutifully closed WorkDB and set it's
pointer to Nothing.

Of course, once WorkDB went "Poof", the .RecordSet I had opened
also went the great bit bucket in the sky.

Solution: Move the Dim for "WorkDB" out of Form_Open() and up to
the form level as "mWorkDB" and don't mess with it until
Form_Close().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top