|
-
Jun 23rd, 2006, 03:01 PM
#1
Thread Starter
Hyperactive Member
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
-
Jun 23rd, 2006, 03:11 PM
#2
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 = ????).
-
Jun 23rd, 2006, 03:23 PM
#3
Thread Starter
Hyperactive Member
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
-
Jun 23rd, 2006, 03:28 PM
#4
Thread Starter
Hyperactive Member
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???
-
Jun 23rd, 2006, 03:43 PM
#5
Thread Starter
Hyperactive Member
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.
-
Jun 23rd, 2006, 04:46 PM
#6
Re: I get error object variable or with block variable not set
I can't see a problem with the code I'm afraid.
-
Jun 23rd, 2006, 09:32 PM
#7
Addicted Member
Re: I get error object variable or with block variable not set
 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?
-
Jun 24th, 2006, 02:23 AM
#8
Thread Starter
Hyperactive Member
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.
-
Jun 24th, 2006, 03:03 AM
#9
Hyperactive Member
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???
-
Jun 24th, 2006, 10:20 AM
#10
Thread Starter
Hyperactive Member
Re: I get error object variable or with block variable not set
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|