Solved

Problem in Adding and Removing controls in VB6

Posted on 2003-11-21
7
1,599 Views
Last Modified: 2007-12-19
I am trying to add and remove controls dynamically in VB6
I could add it by using Controls.Add
But when I try to remove the control using Controls.Remove, I get the following error:
Unable to unload within this context (Error 365)
Any help on this will greatly be appreciated!!!
0
Comment
Question by:lavan_8
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9799666
Where do you try this (which event) ... ?

Because, in some cases, you can't do it, ...

Maybe this Microsoft-Article helps:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vamsgldcantunloadhere.asp
0
 
LVL 1

Author Comment

by:lavan_8
ID: 9799790
Thanks for the prompt answer but I had already gone through that aritcle

This happens in the click event of a combo control.

I had also commented the Unload statements but it didnt help.
When I create the controls dynamically, I had given a prefix of dyn for the names.
I am able to set the visible property of the control but can't remove it.

                For Each x In Controls
                    If Left(x.name, 3) = "dyn" Then
                        Controls.Remove x
                        'x.Visible = False
                    End If
                Next

When it reaches the statement,  Controls.Remove x, the errror "Unable to unload within this context" pops up.

Is there anyother way in which I can remove the controls??

It is essential I remove it and since I added them using the Controls.Add method I have to use the Controls.Remove method to remove it!

Thanks in advance for the help.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9799894
Try this ...

Replace this line
Controls.Remove x

with this line
Controls.Remove x.Name

Hope this helps
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:lavan_8
ID: 9799942
Wish it did - but sorry to say - it doesn't :(
I get the same error.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9800002
How do you create them?

With me, it just works fine!
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 9800101
In the click event of your combo control, start (or enabled) a timer. In the timer event, put your code to remove the dynamic controls.
0
 
LVL 1

Author Comment

by:lavan_8
ID: 9800727
Thank you wsteegmans and emoreau for the answers.
The timer thingy did the trick.
I can now remove the controls at run time
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

777 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