Solved

Problem in Adding and Removing controls in VB6

Posted on 2003-11-21
7
1,601 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

808 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