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

  • Thread starter Thread starter Bre-x
  • Start date Start date
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
 
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.
 
Back
Top