Sharing Info Between Templates

G

Gordon Bentley-Mix

I'm sure this can be done, but I've not done it before and would appreciate a little direction before I dive in.

I have a process that requires multiple documents to be created based on certain criteria. I envision using a 'main' template - let's call it "the DC" (for Data Collection) - to collect this criteria and the additional information to be used in the creation of the additional documents. Each of the additional documents will be based on a specific template - let's call it "the AD" (for Additional Document - actually one of two templates, but the basic function of these templates is the same), and I need the information collected in the DC to be available to the AD. The DC will collect the criteria/information in an array, and the data in the array will be used for two purposes: first, it will be evaluated to determine how many additional documents need to be created (and which template to use for each); and second, parsed data from the array in the form of two strings will be used by the AD to generate the document. The number of additional documents may vary, but at least one additional document will be created each time the process in the DC is run.

I have a pretty good grip on how to collect the data, how to evaluate it to determine how many of which type of additional document needs to be created, how to create the additional documents, how to parse the data to use in the additional documents, and how to use this data. For example, I know that calling Documents.Add and specifying a particular template will create the additional document, and I know that if the AD contains an AutoNew macro, the code will run automatically. I also know how the AutoNew code should work to make use of the data from the DC.

However, the part I'm not sure about is how to actually pass the data from the DC to the AD code. I haven't tested anything, but my intuition tells me that simply declaring a couple of Public String variables won't do the trick; these variables will only be available to the code in which they are declared and not to the code in another template. I suspect that something like an .ini file or the registry or a global constant might be required, but I've not worked with any of these before. Does anyone have any suggestions on the best approach? And would you happen to know of a resource I can look to for some direction on how to implement it?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
 
D

Doug Robbins - Word MVP on news.microsoft.com

Hi Gordon,

I am not sure exactly what you are doing, but I would be inclined to load all of the information from the array into a listbox on a userform in DC and then by iterating through the records in the listbox, I would have code determine which AD template to be used and the number of documents to be created from it. In the AD templates, I would have docvariable fields in the locations where I wanted each of the two strings of data to appear and I would have code in the userform set the Values of variables in each AD document created and update the fields in those documents so that the data from the strings would appear in the docvariable fields.

I don't see that you necessarily need any code in the AD templates themselves.

But maybe I do not understand the full situation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I'm sure this can be done, but I've not done it before and would appreciate a little direction before I dive in.

I have a process that requires multiple documents to be created based on certain criteria. I envision using a 'main' template - let's call it "the DC" (for Data Collection) - to collect this criteria and the additional information to be used in the creation of the additional documents. Each of the additional documents will be based on a specific template - let's call it "the AD" (for Additional Document - actually one of two templates, but the basic function of these templates is the same), and I need the information collected in the DC to be available to the AD. The DC will collect the criteria/information in an array, and the data in the array will be used for two purposes: first, it will be evaluated to determine how many additional documents need to be created (and which template to use for each); and second, parsed data from the array in the form of two strings will be used by the AD to generate the document. The number of additional documents may vary, but at least one additional document will be created each time the process in the DC is run.

I have a pretty good grip on how to collect the data, how to evaluate it to determine how many of which type of additional document needs to be created, how to create the additional documents, how to parse the data to use in the additional documents, and how to use this data. For example, I know that calling Documents.Add and specifying a particular template will create the additional document, and I know that if the AD contains an AutoNew macro, the code will run automatically. I also know how the AutoNew code should work to make use of the data from the DC.

However, the part I'm not sure about is how to actually pass the data from the DC to the AD code. I haven't tested anything, but my intuition tells me that simply declaring a couple of Public String variables won't do the trick; these variables will only be available to the code in which they are declared and not to the code in another template. I suspect that something like an .ini file or the registry or a global constant might be required, but I've not worked with any of these before. Does anyone have any suggestions on the best approach? And would you happen to know of a resource I can look to for some direction on how to implement it?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
 
G

Gordon Bentley-Mix

Mmm... not quite Doug.

The information in the array is being collected _through_ the UserForm - although I will use a ListBox for "managing" the information; e.g. editing, deleting, etc. I do this a lot, so I'm pretty comfortable with it.

The tricky bit with the multiple AD templates is not all the documents will be identical. Each will use a slightly different subset of the data collected through the DC.

Perhaps an example will make it clearer:

The data being collected is basically the name of an entity and the entity type; e.g. Individual, Company or Trust. Let's say I collect one instance of each. My data set looks something like this:

Bob Smith - Individual
Smith Inc - Company
The Smith Trust - Trust

Now what I need is to send letters to the Company and the Trust _only_; Individuals don't get letters. However, the letters do need to include information about the other entities. In addition, the letter to the Company and the Letter to the Trust are slightly different, so they use different templates - but mostly it's just differences in boilerplate, and the actual use of the information about the other entities is identical. Examples (highly simplified):

LETTER TO COMPANY (based on Company AD template)

To: Smith Inc

You need to know something about Bob Smith and The Smith Trust.

LETTER TO TRUST (based on Trust AD template)

To: The Smith Trust

You need to know something about Bob Smith and Smith Inc.

As you can see, I need to pass information from the DC to the ADs as follows:

* To Company AD - String 1: "Smith Inc"; String 2: "Bob Smith and The Smith Trust"
* To Trust AD - String 1: "The Smith Trust"; String 2: "Bob Smith and Smith Inc"

There could be an unlimited number of entities of any type in any combination (although in practical application there generally will never be more than three of any particular type nor more than six in total), but they will all always be shared in a similar fashion.

I can do all of this - collect the data, sort and "package" it, create the additional docs, etc. - but I just don't know how to pass the data from the DC to the ADs, which is basically this part of your recommended approach: "...code in the userform set the Values of variables in each AD document created..."

I'll keep poking at it myself, but if you (or anyone else) have any suggestions...
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!

Hi Gordon,

I am not sure exactly what you are doing, but I would be inclined to load all of the information from the array into a listbox on a userform in DC and then by iterating through the records in the listbox, I would have code determine which AD template to be used and the number of documents to be created from it. In the AD templates, I would have docvariable fields in the locations where I wanted each of the two strings of data to appear and I would have code in the userform set the Values of variables in each AD document created and update the fields in those documents so that the data from the strings would appear in the docvariable fields.

I don't see that you necessarily need any code in the AD templates themselves.

But maybe I do not understand the full situation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I'm sure this can be done, but I've not done it before and would appreciate a little direction before I dive in.

I have a process that requires multiple documents to be created based on certain criteria. I envision using a 'main' template - let's call it "the DC" (for Data Collection) - to collect this criteria and the additional information to be used in the creation of the additional documents. Each of the additional documents will be based on a specific template - let's call it "the AD" (for Additional Document - actually one of two templates, but the basic function of these templates is the same), and I need the information collected in the DC to be available to the AD. The DC will collect the criteria/information in an array, and the data in the array will be used for two purposes: first, it will be evaluated to determine how many additional documents need to be created (and which template to use for each); and second, parsed data from the array in the form of two strings will be used by the AD to generate the document. The number of additional documents may vary, but at least one additional document will be created each time the process in the DC is run.

I have a pretty good grip on how to collect the data, how to evaluate it to determine how many of which type of additional document needs to be created, how to create the additional documents, how to parse the data to use in the additional documents, and how to use this data. For example, I know that calling Documents.Add and specifying a particular template will create the additional document, and I know that if the AD contains an AutoNew macro, the code will run automatically. I also know how the AutoNew code should work to make use of the data from the DC.

However, the part I'm not sure about is how to actually pass the data from the DC to the AD code. I haven't tested anything, but my intuition tells me that simply declaring a couple of Public String variables won't do the trick; these variables will only be available to the code in which they are declared and not to the code in another template. I suspect that something like an .ini file or the registry or a global constant might be required, but I've not worked with any of these before. Does anyone have any suggestions on the best approach? And would you happen to know of a resource I can look to for some direction on how to implement it?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
 
D

Doug Robbins - Word MVP on news.microsoft.com

I assume that you are able to construct the respective String1 and String2 for each case

Then use

Dim target as Document
Set target = Documents.Add("AD Template")
WIth target
.Variables(varString1).Value = String1
.Variables(varString2).Value = String2
.Range.Fields.Update
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Mmm... not quite Doug.

The information in the array is being collected _through_ the UserForm - although I will use a ListBox for "managing" the information; e.g. editing, deleting, etc. I do this a lot, so I'm pretty comfortable with it.

The tricky bit with the multiple AD templates is not all the documents will be identical. Each will use a slightly different subset of the data collected through the DC.

Perhaps an example will make it clearer:

The data being collected is basically the name of an entity and the entity type; e.g. Individual, Company or Trust. Let's say I collect one instance of each. My data set looks something like this:

Bob Smith - Individual
Smith Inc - Company
The Smith Trust - Trust

Now what I need is to send letters to the Company and the Trust _only_; Individuals don't get letters. However, the letters do need to include information about the other entities. In addition, the letter to the Company and the Letter to the Trust are slightly different, so they use different templates - but mostly it's just differences in boilerplate, and the actual use of the information about the other entities is identical. Examples (highly simplified):

LETTER TO COMPANY (based on Company AD template)

To: Smith Inc

You need to know something about Bob Smith and The Smith Trust.

LETTER TO TRUST (based on Trust AD template)

To: The Smith Trust

You need to know something about Bob Smith and Smith Inc.

As you can see, I need to pass information from the DC to the ADs as follows:

* To Company AD - String 1: "Smith Inc"; String 2: "Bob Smith and The Smith Trust"
* To Trust AD - String 1: "The Smith Trust"; String 2: "Bob Smith and Smith Inc"

There could be an unlimited number of entities of any type in any combination (although in practical application there generally will never be more than three of any particular type nor more than six in total), but they will all always be shared in a similar fashion.

I can do all of this - collect the data, sort and "package" it, create the additional docs, etc. - but I just don't know how to pass the data from the DC to the ADs, which is basically this part of your recommended approach: "...code in the userform set the Values of variables in each AD document created..."

I'll keep poking at it myself, but if you (or anyone else) have any suggestions...
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!

Hi Gordon,

I am not sure exactly what you are doing, but I would be inclined to load all of the information from the array into a listbox on a userform in DC and then by iterating through the records in the listbox, I would have code determine which AD template to be used and the number of documents to be created from it. In the AD templates, I would have docvariable fields in the locations where I wanted each of the two strings of data to appear and I would have code in the userform set the Values of variables in each AD document created and update the fields in those documents so that the data from the strings would appear in the docvariable fields.

I don't see that you necessarily need any code in the AD templates themselves.

But maybe I do not understand the full situation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I'm sure this can be done, but I've not done it before and would appreciate a little direction before I dive in.

I have a process that requires multiple documents to be created based on certain criteria. I envision using a 'main' template - let's call it "the DC" (for Data Collection) - to collect this criteria and the additional information to be used in the creation of the additional documents. Each of the additional documents will be based on a specific template - let's call it "the AD" (for Additional Document - actually one of two templates, but the basic function of these templates is the same), and I need the information collected in the DC to be available to the AD. The DC will collect the criteria/information in an array, and the data in the array will be used for two purposes: first, it will be evaluated to determine how many additional documents need to be created (and which template to use for each); and second, parsed data from the array in the form of two strings will be used by the AD to generate the document. The number of additional documents may vary, but at least one additional document will be created each time the process in the DC is run.

I have a pretty good grip on how to collect the data, how to evaluate it to determine how many of which type of additional document needs to be created, how to create the additional documents, how to parse the data to use in the additional documents, and how to use this data. For example, I know that calling Documents.Add and specifying a particular template will create the additional document, and I know that if the AD contains an AutoNew macro, the code will run automatically. I also know how the AutoNew code should work to make use of the data from the DC.

However, the part I'm not sure about is how to actually pass the data from the DC to the AD code. I haven't tested anything, but my intuition tells me that simply declaring a couple of Public String variables won't do the trick; these variables will only be available to the code in which they are declared and not to the code in another template. I suspect that something like an .ini file or the registry or a global constant might be required, but I've not worked with any of these before. Does anyone have any suggestions on the best approach? And would you happen to know of a resource I can look to for some direction on how to implement it?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
 
G

Gordon Bentley-Mix

"I assume that you are able to construct the respective String1 and String2 for each case"

A safe assumption. ;-P

But is it really that easy? I suppose so, since the newly created document will be loaded into the current process... hmmm...

And if I'd rather use bookmarks than DocVar fields, it should be simple enough to use .Bookmarks.Range.Text = String(x) instead.

Thanks Doug. I'll give it a go and let you know how I get on.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
I assume that you are able to construct the respective String1 and String2 for each case

Then use

Dim target as Document
Set target = Documents.Add("AD Template")
WIth target
.Variables(varString1).Value = String1
.Variables(varString2).Value = String2
.Range.Fields.Update
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Mmm... not quite Doug.

The information in the array is being collected _through_ the UserForm - although I will use a ListBox for "managing" the information; e.g. editing, deleting, etc. I do this a lot, so I'm pretty comfortable with it.

The tricky bit with the multiple AD templates is not all the documents will be identical. Each will use a slightly different subset of the data collected through the DC.

Perhaps an example will make it clearer:

The data being collected is basically the name of an entity and the entity type; e.g. Individual, Company or Trust. Let's say I collect one instance of each. My data set looks something like this:

Bob Smith - Individual
Smith Inc - Company
The Smith Trust - Trust

Now what I need is to send letters to the Company and the Trust _only_; Individuals don't get letters. However, the letters do need to include information about the other entities. In addition, the letter to the Company and the Letter to the Trust are slightly different, so they use different templates - but mostly it's just differences in boilerplate, and the actual use of the information about the other entities is identical. Examples (highly simplified):

LETTER TO COMPANY (based on Company AD template)

To: Smith Inc

You need to know something about Bob Smith and The Smith Trust.

LETTER TO TRUST (based on Trust AD template)

To: The Smith Trust

You need to know something about Bob Smith and Smith Inc.

As you can see, I need to pass information from the DC to the ADs as follows:

* To Company AD - String 1: "Smith Inc"; String 2: "Bob Smith and The Smith Trust"
* To Trust AD - String 1: "The Smith Trust"; String 2: "Bob Smith and Smith Inc"

There could be an unlimited number of entities of any type in any combination (although in practical application there generally will never be more than three of any particular type nor more than six in total), but they will all always be shared in a similar fashion.

I can do all of this - collect the data, sort and "package" it, create the additional docs, etc. - but I just don't know how to pass the data from the DC to the ADs, which is basically this part of your recommended approach: "...code in the userform set the Values of variables in each AD document created..."

I'll keep poking at it myself, but if you (or anyone else) have any suggestions...
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!

Hi Gordon,

I am not sure exactly what you are doing, but I would be inclined to load all of the information from the array into a listbox on a userform in DC and then by iterating through the records in the listbox, I would have code determine which AD template to be used and the number of documents to be created from it. In the AD templates, I would have docvariable fields in the locations where I wanted each of the two strings of data to appear and I would have code in the userform set the Values of variables in each AD document created and update the fields in those documents so that the data from the strings would appear in the docvariable fields.

I don't see that you necessarily need any code in the AD templates themselves.

But maybe I do not understand the full situation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

I'm sure this can be done, but I've not done it before and would appreciate a little direction before I dive in.

I have a process that requires multiple documents to be created based on certain criteria. I envision using a 'main' template - let's call it "the DC" (for Data Collection) - to collect this criteria and the additional information to be used in the creation of the additional documents. Each of the additional documents will be based on a specific template - let's call it "the AD" (for Additional Document - actually one of two templates, but the basic function of these templates is the same), and I need the information collected in the DC to be available to the AD. The DC will collect the criteria/information in an array, and the data in the array will be used for two purposes: first, it will be evaluated to determine how many additional documents need to be created (and which template to use for each); and second, parsed data from the array in the form of two strings will be used by the AD to generate the document. The number of additional documents may vary, but at least one additional document will be created each time the process in the DC is run.

I have a pretty good grip on how to collect the data, how to evaluate it to determine how many of which type of additional document needs to be created, how to create the additional documents, how to parse the data to use in the additional documents, and how to use this data. For example, I know that calling Documents.Add and specifying a particular template will create the additional document, and I know that if the AD contains an AutoNew macro, the code will run automatically. I also know how the AutoNew code should work to make use of the data from the DC.

However, the part I'm not sure about is how to actually pass the data from the DC to the AD code. I haven't tested anything, but my intuition tells me that simply declaring a couple of Public String variables won't do the trick; these variables will only be available to the code in which they are declared and not to the code in another template. I suspect that something like an .ini file or the registry or a global constant might be required, but I've not worked with any of these before. Does anyone have any suggestions on the best approach? And would you happen to know of a resource I can look to for some direction on how to implement it?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no membership required!
 

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