Results 1 to 10 of 10

Thread: I get error object variable or with block variable not set

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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:
    1. Private Sub Form_Close()
    2. On Error GoTo Err_Form_Close
    3.  
    4. 'clsMouseWheel.SubClassUnHookForm
    5. Set clsMouseWheel.Form = Nothing
    6. Set clsMouseWheel = Nothing
    7.  
    8. Exit_Form_Close:
    9.     Exit Sub
    10.  
    11. Err_Form_Close:
    12.     MsgBox Err.Description
    13.     Resume Exit_Form_Close
    14. End Sub

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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 = ????).

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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:
    1. Option Compare Database
    2. Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel
    3.  
    4. Private Sub Form_Load()
    5. Set clsMouseWheel = New MouseWheel.CMouseWheel
    6. Set clsMouseWheel.Form = Me
    7. clsMouseWheel.SubClassHookForm
    8. End Sub
    9.  
    10. Private Sub Form_Close()
    11. On Error GoTo Err_Form_Close
    12.  
    13. clsMouseWheel.SubClassUnHookForm
    14. Set clsMouseWheel.Form = Nothing
    15. Set clsMouseWheel = Nothing
    16.  
    17. Exit_Form_Close:
    18.     Exit Sub
    19.  
    20. Err_Form_Close:
    21.     MsgBox Err.Description
    22.     Resume Exit_Form_Close
    23. End Sub
    24.  
    25. Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
    26. MsgBox "You cannot use the mouse wheel to scroll records."
    27. Cancel = True
    28. End Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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???

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: I get error object variable or with block variable not set

    I can't see a problem with the code I'm afraid.

  7. #7
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    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:
    1. Private Sub Form_Close()
    2. On Error GoTo Err_Form_Close
    3.  
    4. 'clsMouseWheel.SubClassUnHookForm
    5. Set clsMouseWheel.Form = Nothing
    6. Set clsMouseWheel = Nothing
    7.  
    8. Exit_Form_Close:
    9.     Exit Sub
    10.  
    11. Err_Form_Close:
    12.     MsgBox Err.Description
    13.     Resume Exit_Form_Close
    14. 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?




    If you find any of my posts of good help, please rate it

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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.

  9. #9
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    266

    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???

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width