How to pass userform data to a new document?

T

Thom

1st time user.. I have a custom userform that creates multiple records
for my user to select from that will insert their name and address in
the header and footer. This works fine for this template, but I want
to open a new document based on a similar template and allow the user
to select another name from the userform to be placed in the header and
footer. When the new document is opened, the userform does not have
any data.

Is it possible for this template with the custom userform to keep its
data and present it in the new document, if so how?

Thanks a many!

PS. The userform is opened when the user clicks a toolbar button, and I
am using Word 2003.
 
E

Ed

Hi, Thom. It sounds like the UserForm is getting its data from the
template, yes? So when the UserForm is opened from a template without this
data, the necessary controls are not populated, and the data isn't there to
write to the new document?

Since a form is attached to a template, and I don't think you can close the
template without losing the form, I would assume the template is still open,
and your data then is still available. It sounds like you're populating a
control (ListBox?) when you create a new document, and you are actually
reading the data from the doc. A new doc from the data-filled template will
of course have the data - a new doc from another template won't.

If this is your scenario, try populating your ListBox in the Form_Initialize
event. If you have to, you can open a new doc from the current template,
but not show it, and then if the user decides to create a doc from a
different template, you can close that one, but your data would already be
read into your control.

Ed
 
T

Thom

Hi Ed,
Thank you so much for your attention. To be more specific about what I want
to do for my user, this might help clarify. Let's say, the userform has
fields, Product type, Product Name and cost. The user would select which
Product type, Product Name they want to be in the new document from the
userform and click continue. When they click continue, a new document would
open and the Product type and Name they selected from the previous template
would then appear in the new document.

What do you think?
 
E

Ed

Thom:

When you say "template", do you mean an actual Word template file saved with
a .dot extension? Or are you using the term to mean a "master document"?

Creating a new blank document is easy. If you mean you want to overwrite
the date in the open "master" and SaveAs a different, new, document, that's
also easy, but different.

What are you using to mark the places where the Product Type and Product
Name will appear? Are they going to be put into table cells? bookmarks?
The first and second paragraphs?

Ed
 
T

Thom

This is a template with .dot extension. What I have been able to
declare some public variables and assign them to doc variables when the
new document opens. But what is happening now, is I'm opening a
template and not a doc.
Help with:
1. Open the new document as a document and not a template.

Set docNew = Templates("c:\ProductNotice.dot").OpenAsDocument

ActiveDocument.Variables("dvProductName") = gsPName

ActiveDocument.Variables("dvProductType") = gsPType

Thanks..
 
E

Ed

Hi, Thom.
1. Open the new document as a document and not a template.

Set docNew = Templates("c:\ProductNotice.dot").OpenAsDocument

Try
Set docNew = Documents.Add("c:\ProductNotice.dot")

Then don't use ActiveDocument - use docNew as your document object.

I assume gsPName and gsPType are strings that contain your text? Have you
checked them to make sure they contain the correct info?

Ed
 

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