Unloading a User Form

D

Dave

Hi

I have created some User Forms that populate a variety of templates e.g
letters, memo's etc. However, whenever someone opens an old document
that has been produced with a User Form, and has then been saved, the
User Form appears again! Is there a way of stopping that happening?

Thanks

Dave
 
J

Jonathan West

Dave said:
Hi

I have created some User Forms that populate a variety of templates e.g
letters, memo's etc. However, whenever someone opens an old document that
has been produced with a User Form, and has then been saved, the User Form
appears again! Is there a way of stopping that happening?


What means do you use to make the userform show automatically?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

Dave

Hi Jonathan

In my templates I use:

Sub AutoNew()
'
' AutoNew Macro
' Macro created 28/02/05 by DG .
'
frmLetter.Show
End Sub

Dave
 
J

Jonathan West

OK, that's the right way to do it. I assume that the AutoNew macro is in the
VBA project in the template, along with the UserForm itself.

Is there an AutoOpen macro as well?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Dave said:
Yes to all of the questions re the AutoNew, and there is no AutoOpen

Hmmm. Is there a Document_Open event in the ThisDocument module in the
template?

When the document is re-opened, does the filename of the document appear on
the window caption, or does it say "Document n"?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

Dave

Snag. I am at home and the problem templates are at work! I am
wondering if when I click OK and unload the userform to generate my
document, I should be doing something else at that point. Should
another line of code follow the Unload Me line?

Thanks

Dave
 
J

Jonathan West

Dave said:
Snag. I am at home and the problem templates are at work! I am wondering
if when I click OK and unload the userform to generate my document, I
should be doing something else at that point. Should another line of code
follow the Unload Me line?

No, Unload Me is the right thing to use to close the UserForm.

Something else, somewhere, must be causing the Userform to show up again
when the document is opened. The two obvious candidates are an Auto macro,
or an event proceure.

There's a way we can smoke this out. Change the name of the form in the
properties pane in the VBA editor from frmLetter to something else, and make
the matching change in the AutoNew macro. Make no other changes at all. Save
the template and then try to reproduce the problem. With any luck, you will
trigger an error as some piece of code tries to run a nonexistent form.
Track it down and work out what needs to be changed.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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