Problem in Adding and Removing controls in VB6

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!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Where do you try this (which event) ... ?

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

Maybe this Microsoft-Article helps:
lavan_8Author Commented:
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(, 3) = "dyn" Then
                        Controls.Remove x
                        'x.Visible = False
                    End If

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.
Try this ...

Replace this line
Controls.Remove x

with this line
Controls.Remove x.Name

Hope this helps
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

lavan_8Author Commented:
Wish it did - but sorry to say - it doesn't :(
I get the same error.
How do you create them?

With me, it just works fine!
Éric MoreauSenior .Net ConsultantCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lavan_8Author Commented:
Thank you wsteegmans and emoreau for the answers.
The timer thingy did the trick.
I can now remove the controls at run time
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.