Unload Error

Posted on 2005-05-16
Last Modified: 2012-08-13
I have an array of a couple of sliders and checkboxes on a VB6 form. I created them dynamically (programatically) using this code:

For i = 1 to 10
    Load Slider1 (i)
    Load CheckBox1 (i)
Next i

The problem comes in when I try to unload the controls. I start from the highest indexed one (10) and make my way down:

For i = Slider1.UBound To 1 Step -1
    Unload Slider1 (i)
    Unload CheckBox1 (i)
Next i

As soon as it executes the first loop, I get this error message:

Run-time Error '365':
Unable to unload within this context.

Any ideas?
Question by:SETP
    LVL 44

    Accepted Solution

    Hi SETP,

    Are you trying to unload the sliders from within the click event of on of the slider controls? This is a rare problem but there are certain controls that cannot be unloaded from within certain events. If you cannot change the event from which it is being unloaded then the only solution ( a bit of a kludge really ) is to add a timer control and fire this a very short period after the event finishes. This will then allow you to unload the controls.

    Tim Cottee

    Author Comment

    I'm unloading them from the click event of a ComboBox. It's not a normal slider though - it's an xFxSlider from xFxJumpStart, but it has the exact same problem with the checkbox (standard Windows checkbox) and Label (standard Windows Label)...

    Author Comment

    WOW!!! Apparently you cannot unload controls from the Change, Click, or DropDown events of a ComboBox! What the hell??? Why on earth not??? Here is the full list if events you cannot unload controls from:

    the Paint event for the form or for a control on the form that has the Paint event.
    the Change, Click, or DropDown events of a ComboBox.
    the Scroll event of an HScrollBar or VScrollBar control.
    the Resize event of a Data, Form, MDIForm, or PictureBox control.
    the Resize event of an MDIForm that is trying to unload an MDI child form.
    the RePosition or Validate event of a Data control.
    the ObjectMove event of an OLE Container control.


    There's also a thread on Experts-Exchange from someone who had the same problem but noone could explain to him why Microsoft put these restrictions in Visual Basic 6.

    Thanks for you help TimCottee

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now