Useform won't Show with dynamically added controls

P

pinkfloydfan

Hi there

Using Windows XP, Excel 2003

I have created a userform to which I dynamically add controls as my
vba program runs. Having tested it, all the controls are added
correctly (and later deleted). However, when I next added the line
Myuserform.Show in order to display the form, I obtain the error:
"Invalid forward reference, or reference to uncompiled type".

When I step through the program again the error occurs once I try to
add the first control to the form before I even try and show the form.

Does anyone know what is going on here please and how to fix it?

Many Thanks
Lloyd
 
D

Dave Peterson

First, I've never seen this error -- so everything I suggest is gonna be a guess.

Have you tried compiling the project (Debug|Compile in the VBE)?

Do you use any non-builtin controls or are they all the "normal" controls?

Your answers won't help me, but maybe they'll help some other potential responder.
 
P

pinkfloydfan

Hi Dave

I have tried Debut/Compile and running it again and that makes no
difference.

I am only adding a series of built-in checkboxes and labels.

The weird thing is that if I comment out the line "Myuserform.Show" it
does what it's supposed to do...once that line is added in then it
crashes as soon as I try and add the first control.

I am completely lost now!
 
D

Dave Peterson

This may not work for you, but if you remove the code that adds the controls,
can you show the userform successfully?

If yes, maybe you could add the controls, but hide them when the form loads.
Then show them later (instead of adding them).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top