View code of new control - missing

G

George Seese

When I add a new control such as a command button on a user form, and I
click on View Code, VBA normally inserts "starter" code.

Sometimes this does not happen. If I copy a command button, and View Code,
in VBA the starter code is not shown and the cursor is at the very top of
the form's code.
If I restart Word, the starter code is then shown.
Is there an easier way to have VBA recognize the new control and show the
new code?

Thanks,
George
 
W

Word Heretic

G'day "George Seese" <[email protected]>,

Run a small sub that declares the form and kills it.

Eg

Sub Refresher()
Dim MyForm as UserForm1
Set MyForm = New UserForm1
Set MyForm = Nothing
End Sub

Next, ensure you always destroy all objects, this will minimise
instances of your form in memory hanging around painfully.

George Seese said:
When I add a new control such as a command button on a user form, and I
click on View Code, VBA normally inserts "starter" code.

Sometimes this does not happen. If I copy a command button, and View Code,
in VBA the starter code is not shown and the cursor is at the very top of
the form's code.
If I restart Word, the starter code is then shown.
Is there an easier way to have VBA recognize the new control and show the
new code?

Thanks,
George

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 
G

George Seese

I was loooking for:
1. Does this happen to others? Is it a common problem?
2. A possible explanation for the problem?
3. An easier workaround than restarting Word.

Your suggestion to write a sub - isn't that more complicated? Do you suggest
writing this sub in all projects?

Your suggestion to destroy all objects. What do you mean? I'm creating
controls on a userform. When do I destroy any object?
Thanks,
George
 
M

Mark Tangard

George,

Destroying objects basically means setting any object variables
you've created equal to 'Nothing' when you're done with them.
(Most often, when you see this properly adhered to at all, it'll
be with Range objects, commandbar-related objects, and the like;
but the MyForm variable in the Steve's code is another example.
You may also this expressed as "releasing" all object variables.)

About the starter code: I only rarely want the starter code VBA
furnishes (and most often wish it could be turned off). But I
can't say I've ever seen it behave inconsistently. Perhaps the
most reliable way to get the starter code is to double-click the
newly created (codeless) control.
 
G

George Seese

Steve,

I was looking for:
1. If this is a problem others have.
2. What possibly causes the problem.
3. An easier workaround (most important).

Could you explain how the sub is executed? Do you link it to a menu option
or shortcut keys?

Your suggestion for destroying objects. What do you mean? I've been doing
VBA for years and have never "destroyed" an object. But I'm open to new
ideas, if you could provide more details.

Thanks,
George
 
W

Word Heretic

G'day "George Seese" <[email protected]>,

1 Yes
2 Old instances of it in memory from bad object destructions - read
original message closely
3 Provided already.

Here's a more detailed (technical) explanation seeing as you obviously
thirst for knowledge:

Let's take a nice example. An already existing, being developed
module.

We start Word. Word compiles the project if it isn't done already.
There are no syntax errors so it compiles nicely. Thus it now 'knows'
that MyObject has a .ScrewUp method. When I declare a MyObject,
..ScrewUp appears in the dropdown.

I run a test and do this. Whether I have destroyed my objects or not,
we have now 'enforced' the latest 'definition' of that object. Word
now believes it knows everything about it.

So, I go and add .BallsUp as a new method. (Seeing as I write so many
bugs, I figure its best to name my routines accordingly :) ) For the
beginners, a method is just a public sub or function inside the object
definition.

So, we go down to the calling routine and try adding in a .BallsUp to
our object. It doesn't appear! "Why not??!!??" asks George, ripping
his hair out in frustration at this strange problem.

Look up above in this message... oh... Word already thinks it knows
about this object. So, we have to force a 'new look' at what the
object is.

We run the simple sub, redeclaring our object, and Word now
'refreshes' its knowledge about this object. Our .ballsup now appears
nicely.


<Bows>





George Seese said:
Steve,

I was looking for:
1. If this is a problem others have.
2. What possibly causes the problem.
3. An easier workaround (most important).

Could you explain how the sub is executed? Do you link it to a menu option
or shortcut keys?

Your suggestion for destroying objects. What do you mean? I've been doing
VBA for years and have never "destroyed" an object. But I'm open to new
ideas, if you could provide more details.

Thanks,
George

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 

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