I get error object variable or with block variable not set
I get an error message in VBA saying Object Variable or With Block Variable Not set whenever I try to close the form.
It highlights the line I have commented in green in the code below. I just commented it right now so you can see it. It's not commented out when I run the program.
The code below is for an ActiveX I created with vb 6.0 which prevents the user from using the scroll button on the mouse to move through records. When they try to use the scroll button they get a pop up that says sorry you can scroll through records using the mouse scroll.
Anyways, I used this exact coding and ActiveX I created in a previous program and it worked fine with no error pop-ups. However, in this new program it's giving me that error.
VB Code:
Private Sub Form_Close()
On Error GoTo Err_Form_Close
'clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
Exit_Form_Close:
Exit Sub
Err_Form_Close:
MsgBox Err.Description
Resume Exit_Form_Close
End Sub
Re: I get error object variable or with block variable not set
The error "Object Variable or With Block Variable Not set" means that you are using an object (the bit before the dot) without it actually being an object in scope.
Presumably you have declared the clsMouseWheel variable (more specifically, object variable) somewhere that is out of scope (possibly within a particular sub), or the object has not been created yet (using Set clsMouseWheel = ????).
Re: I get error object variable or with block variable not set
Here is all the coding related to the activex i created for that form. The program has multiple forms, so I put this coding below on each form where the user was able to input data so they couldn't accidently use their scroll button and scroll to another record.
The activex works....if they use the scroll button it gives them that pop thats no, can't do that....but on this program i get that error message about not being set whenever i close any of the forms with the ocding below, yet i didn't get it on the last program i wrote and used the exact same coding. yes, i did reference it in the references option.
VB Code:
Option Compare Database
Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel
Private Sub Form_Load()
Set clsMouseWheel = New MouseWheel.CMouseWheel
Set clsMouseWheel.Form = Me
clsMouseWheel.SubClassHookForm
End Sub
Private Sub Form_Close()
On Error GoTo Err_Form_Close
clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
Exit_Form_Close:
Exit Sub
Err_Form_Close:
MsgBox Err.Description
Resume Exit_Form_Close
End Sub
Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
MsgBox "You cannot use the mouse wheel to scroll records."
Cancel = True
End Sub
Re: I get error object variable or with block variable not set
Here's a thought.....
these forms that have this coding are subforms.
so, when i close the form while running the program which gives me that error I'm actually closing the main form which has these subforms in them.
if you look at the coding above i use the coding ME to refer to the current form. I wonder if that has anything to do with it???
Re: I get error object variable or with block variable not set
Scratch that theory. I tried replacing Me with the the subform name, mainform name, mainform.subform but it still didn't solve it.
Re: I get error object variable or with block variable not set
I can't see a problem with the code I'm afraid. :confused:
Re: I get error object variable or with block variable not set
Quote:
Originally Posted by lilmark
I get an error message in VBA saying Object Variable or With Block Variable Not set whenever I try to close the form.
It highlights the line I have commented in green in the code below. I just commented it right now so you can see it. It's not commented out when I run the program.
The code below is for an ActiveX I created with vb 6.0 which prevents the user from using the scroll button on the mouse to move through records. When they try to use the scroll button they get a pop up that says sorry you can scroll through records using the mouse scroll.
Anyways, I used this exact coding and ActiveX I created in a previous program and it worked fine with no error pop-ups. However, in this new program it's giving me that error.
VB Code:
Private Sub Form_Close()
On Error GoTo Err_Form_Close
'clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
Exit_Form_Close:
Exit Sub
Err_Form_Close:
MsgBox Err.Description
Resume Exit_Form_Close
End Sub
Hey lilmark,
When you say "in this NEW program, it doesn't work" what new program are you talking about? And what was the old program?
Re: I get error object variable or with block variable not set
The old program was just a single form to record data to a table that was keyed in.
This new program does the same thing, except it has a lot more forms and subforms.
Re: I get error object variable or with block variable not set
code is working fine with me
is there a form that called this form???
Re: I get error object variable or with block variable not set
Quote:
Originally Posted by noshaba
code is working fine with me
is there a form that called this form???
Called which form? The coding is on the subforms which are placed on the main form. So, the main form is calling these subforms if that's what you mean.