?
Solved

Problem in Adding and Removing controls in VB6

Posted on 2003-11-21
7
Medium Priority
?
1,618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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