Useform won't Show with dynamically added controls

  • Thread starter Thread starter pinkfloydfan
  • Start date Start date
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
 
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.
 
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!
 
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).
 
Back
Top