Object Variable not set .....???

B

Bre-x

Hi,
I am using MS Access 2000 and i have a problem everytime i try to close my
form

Err.number = 91
Err = Object Variable not set or With block variable not set

Private Sub Form_Open(Cancel As Integer)
Dim rsAlwaysOpen As Recordset
Set rsAlwaysOpen = CurrentDb.OpenRecordset("DB_Users")
End Sub

Private Sub Form_Close()
On Error GoTo Err_Form_Close
Dim rsAlwaysOpen As Recordset
rsAlwaysOpen.Close
Set rsAlwaysOpen = Nothing
DoCmd.Maximize
Exit_Form_Close:
Exit Sub
Err_Form_Close:
MsgBox Err.Description & " " & Err.Number
Resume Exit_Form_Close
End Sub

Regards,

Bre-x
 
S

Sandra Daigle

You've got a problem with variable scope - if you declare (dim) a variable
within a procedure, then it is only available in that procedure. If declare
it in the Module header, and using either the Dim or Private statements,
then it will be available to all procedures within that module.

If you want rsAlwaysOpen to be open throughout the life of the form, you
should declare it in the module header and remove the Dim statements from
the Open and Close events.
 

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