Error #365: Unable to unload within this context
-
Monday, March 06, 2006 9:17 PM
Hi.
I have a control array of labels designed to replicate the functionality of a datagrid control (because DataGrid is notoriously slow to update). I have a function, populateLabels, which upon activating the form is called.
populateLables unloads all the control array elements after 0, opens a recordset and creates new labels for each field, for each row returned by the recordset.
The problem comes when I try and unload the controls after they've been created.
I have different forms for editing fields in the database, and when the user closes one of the editing forms, the Form_Activate for the main form is called and attempts to clear the controls and repopulate to show the updated data.
However, instead of the desired functionality, I get the following error:
"Runtime Error 365: Unable to unload in this context".
I checked the help, and none of it was helpful. It does mention the error and possible causes, but my cause was not listed....
"There is an Unload statement in the Paint event" -- nope
There is an Unload statement in the Change, Click, or DropDown events of a ComboBox." -- nope
"There is an Unload statement in the Scroll event of an HScrollBar or VScrollBar control" -- nope
"There is an Unload statement in the Resize event of a Data, Form, MDIForm, or PictureBox control" -- nope
"There is an Unload statement in the Resize event of an MDIForm that is trying to unload an MDI child form." -- nope
"There is an Unload statement in the RePosition or Validate event of a Data control."-- nope
"There is an Unload statement in the ObjectMove event of an OLE Container control."-- nopeI've tried putting the repopulation code in a timer and calling it a second after the form has been activated, but I get the same error. I tried creating a command button that clears and repopulates and I get the same error.
So ah... What exactly is the "bad context" I’m running into ?
What is valid context for unloading control arrays ?Thanks all.
-Tyler Waters
All Replies
-
Monday, March 06, 2006 9:25 PM
a HA!
I figured it out.
I have a combo box that controls which dataset the user views on the main form.
Upon selecting a different dataset from the combobox, I have the labels repopulating.I changed this so the Click event enables the timer and it now works fine...
"There is an Unload statement in the Change, Click, or DropDown events of a ComboBox."
Interesting to note that even when a function is called from the above event, it still causes the crash...
-
Monday, October 23, 2006 12:37 AM
This is almost too bizarre to be true!!!
I've just had an almost identical problem and spent the last couple of hours tracking it down to this most rediculous bug!
I even thought about the same solution but dismissed it as just too stupid!
Why does this error occur when you click a combo but not a button???!!!
I assume this is a bug in VB?
Anyway, I'm now going to pollute my code with a similar cludge that involves a timer...
Thanks tswaters for posting this... at least I'm not alone!
-
Wednesday, August 08, 2007 11:45 AMi have created controls dynamically in tab control and when i try to remove those control i am getting same error...
some days before its working fine but now its showing error.... -
Wednesday, August 08, 2007 3:13 PM
How are you removing the controls? If the unload code is called via one of the above object/event combinations, it will cause a crash.... Revise your code so it doesn't rely on those events or if you really can't revise the code, try using a timer ..... a painful cludge, but it works
Can't help you with the "some days before" --um.. you probably changed the code? Things usually don't break randomly for no reason -- especially when they give a specific error message.
-
Friday, August 10, 2007 10:39 PM
Could you send me a snipet of the combo_click code and how you use the timer?
Thanks,
Dave
-
Saturday, August 11, 2007 5:14 PM
it's not brain surgery...this raises an error:
Code Snippetprivate sub form_activate()
load control
end sub
private sub combo1_click()
unload control
end sub
This is the cludge that fixes it:
Code Snippetprivate sub form_load()
timer1.interval=100
end sub
private sub form_activate()
load control
end sub
private sub combo1_click()
timer1.enabled = true
end sub
private sub timer1_timer()
unload control
timer1.enabled=false
end sub
-
Sunday, April 27, 2008 1:37 PMThank you. It would have taken days to figure out this is a VB bug.

