Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

docvariables in a section versus activedocument 1

Status
Not open for further replies.

cramd

Programmer
Mar 28, 2001
214
0
0
US
I have one large document I'll call MASTER, within MASTER I have 80 sections - each section is a page to a different customer. The problem I am having is I insert a docvariables for section1 or page1:

ActiveDocument.Variables.Add(Name:="amount", value:=custAmt)
ActiveDocument.Variables.Add(Name:="desc", Value:=custDesc)
ActiveDocument.Variables.Add(Name:="type", Value:=custType)
ActiveDocument.Fields.Update()

now I insert a page break within the same MASTER document, create letter #2, insert the same variables. When the activedocument is updated for letter #2, it also updates letter#1(or section1) with the same variable information as letter#2. So in the end, I have a MASTER document with 80 pages, and whatever the last customers information had for the above variables, it updates the variable information for all 80 pages; all my customers owe me $80 for the same item.
How can I set docvariable information for each section?
AND I hope this makes some sense to anyone who wants a challenge.
cramd
 
The container for a docvariable is the document. They do not anchor to a page or section.

You should get an error if you try to add a variable with the same name as one that already exists.

You could concatenate the customer's name or ID to the existing variable names to create unique variables for each customer.

Sounds like what you really need is a database.
 
mintjulep:
Your comment: "You should get an error if you try to add a variable with the same name as one that already exists"
I did get this error, so I was deleting and recreating the variables after each read to my database.
Process:
1)Read the database that contains fields custamt,custDesc, and custType
2)Process page1 in the MASTER document, adding variables:
ActiveDocument.Variables.Add(Name:="amount", value:=custAmt)
ActiveDocument.Variables.Add(Name:="desc", Value:=custDesc)
ActiveDocument.Variables.Add(Name:="type", Value:=custType)
ActiveDocument.Fields.Update()
3)Insert page break
4)Read the database
5)Delete variables
(I thought since the first page was now created, I could delete variables, and then re-create the variables for the next page---
6)Create the variables for page2--which I now realize will not work.

It seems the only solution to this will be doing as you suggested, concatenating a unique identifier.
Can I concatenate the name as this:
ActiveDocument.Variables.Add(Name:="amount" + custName, value:=custAmt)

Thanks for your interest in my post!
cramd

 
Hi cramd,

This sounds like a mailmerge application. Is there a reason you are not using Mail Merge?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony,
Welcome back! The reason I'm not using mailmerge, it would be too easy--kidding. You helped me work out project 1, now I've moved on to project 2, a mailmerge would be great if I would be using the same document for all customers. The database that I read from also has a field that indicates which paragraph to insert into my document for that particular customer. In the end I will have many letters (within my MASTER document), each letter(or page) reads different, all based on information in the customer's record, do they order often? do they pay on time? etc. Letter 1 may need the variable information, letter 2 may not - it all depends on the paragraphs that are chosen for that particular customer.
With all that said, (I hope I have not bored you with too much information) I'm thinking as I process the letters, I can concatenate the custnum to the variable, making it unique to that letter within my MASTER document. I'll be testing this now.
cramd
 
Could you please expand on the reason for setting the docvariables?

If I read the post correctly:

a docvariable is set for customer information contained within a specific Section, the source of which is a database.

As Tony pointed out, this may be a mail merge issue. However, I am curious as to why you are setting docvariables? It seems an odd thing to do.

Gerry
 
Gerry,
Your statement is correct: "a docvariable is set for customer information contained within a specific Section, the source of which is a database".
In the MSWORD paragraphs, I have inserted docvariables. Within my vbcode, I assign my database fields to the docvariables, update the fields and all works. A mailmerge will not work with this situation, but the docvariables do.

I have been able to concatenate customer# to the docvariables, making my variables unique to each page (or section) within my large MSWORD document. My MSWORD document has 80 seperate customer pages, different letters, all including the correct variable information.
Thanks for everyone's help once again!
cramd
 
In the MSWORD paragraphs, I have inserted docvariables

really? still seems like an odd process, but yes, it would work. however, my question remains...WHY? Why are you using docvariables? I am curious because there are other methods for holding data in a document.

Gerry
 
Gerry,
Let me add, the database that I read from is DB2, not an Access database. The mailmerge works for some things that we do, but with this application, the mailmerge does not seem to be an option for me. I have learned quite a bit with this project using the docvariables, but you have now raised my curiousity about the other methods for holding data. If you have links that can help me understand these methods, I am interested.
Thanks,
cramd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top