Discussion Locked

Unloading a control array

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a form containing control arrays (labels and checkboxes) created at run time. My problem is that when I try to Unload them I get the error 365 - "Unable to unload within this context". The Unload statement is not called from any of the events noted in MSDN help, but from a subroutine which is in turn called from a click event.

6 replies

by soundbomber

Incidently, the click event which triggers the subroutine is from a combo box. I have noticed that the same code triggered from the click event of a command button works! Get around that one!

by theohkm

It is related to the sequence of the events so some of the events cannot make it work.

Could you list some details of your code ?

Thanks!

by soundbomber

Private Sub Form_Load()
PopulateLabels
End Sub

Private Sub PopulateLabels()
Dim f As Double
For f = 1 To varRecordCount - 1
Load chkReqd(f)
chkReqd(f).Top = chkReqd(f - 1).Top + 300
chkReqd(f).Visible = True
Next

Private Sub cboClient_Click()
UnloadLabels
End Sub

Private Sub UnloadLabels()
Dim f As Double
For f = 1 To varRecordCount - 1
Unload chkReqd(f)
Next

by starchers

I put a timer on my form and enabled it on the click event of the combo box. The timer then calls the events I need it to - specifically to unload controls in an array that was created at run time, then unenables itself. This worked for me.
I also tried calling the click event of a command button from the click event of the combox box and this did not work.

This discussion is closed to new replies.