Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem in Adding and Removing controls in VB6

Posted on 2003-11-21
7
Medium Priority
?
1,622 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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 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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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