Mail Merge an Word file (using data from an Access file)

xuhathdo

New member
Local time
Today, 09:40
Joined
Feb 5, 2014
Messages
4
Hi, I need help.

Here is my situation. I often create contract using mail merge. I have an access file that I want to use as data source for word file. But it does not automatically.

Please download the attached file !

If there are 1 customer and 1 property, I do not need to do anything. Conversely, if there are many customers and many properties, I take time to manipulate.

Firstly, I open the word file. I have to copy and paste paragraphs that I want. Highlight of the original paragraphs is blue.

Secondly, I click 'Insert Word Field' -> select 'Next Record'.

In short, I wish to use VBA in access file to automatically perform the steps that I have outlined.


[FONT=&quot]Thank You.


[/FONT]
 

Attachments

Thanks for your reply !

But I need to use VBA to copy paragraph and select the 'Next Record' in 'Insert Word feild'. For example:

+ Case 1: 1 Customers and 1 Properties
VALUATION​

Today on «Date_Value», at New York:

1/ Customer
1.1 Customer 1:
- Name: «Name»
- ID card: «ID_card»
- Birthday: «Birthday»
- Address: «Address»

2/ Code of Property:
2.1/ Property 1: «CodeProperty»

3/ Land
Code
Category
Address
Area
«CodeProperty»​
«Category_of_Land»​
«Address_of_Land»​
«Area_of_Land»​

4/ Building

Code
Category
Area
«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​

5/Valuation
Code
Category
Area
Value
«CodeProperty»​
«Category_of_Land»​
«Area_of_Land»​
«Land_Value»​
«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Building_Value»​
Total​
«Total_Value»​

Total Value: «Total_Value»$.

+ Case 2: 2 Customers and 3 Properties
VALUATION​

Today on «Date_Value», at New York:

1/ Customer
1.1 Customer 1:
- Name: «Name»
- ID card: «ID_card»
- Birthday: «Birthday»
- Address: «Address»
«Next Record»«Next Record»«Next Record»1.2 Customer 2:
- Name: «Name»
- ID card: «ID_card»
- Birthday: «Birthday»
- Address: «Address»

2/ Code of Property:
2.1/ Property 1: «CodeProperty»
«Next Record»2.2/ Property 2: «CodeProperty»
«Next Record»2.3/ Property 3: «CodeProperty»

3/ Land
Code
Category
Address
Area
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Address_of_Land»​
«Area_of_Land»​
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Address_of_Land»​
«Area_of_Land»​
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Address_of_Land»​
«Area_of_Land»​

4/ Building

Code
Category
Area
«Next Record»«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Next Record»«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Next Record»«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​

5/Valuation
Code
Category
Area
Value
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Area_of_Land»​
«Land_Value»​
«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Building_Value»​
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Area_of_Land»​
«Land_Value»​
«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Building_Value»​
«Next Record»«CodeProperty»​
«Category_of_Land»​
«Area_of_Land»​
«Land_Value»​
«CodeProperty»​
«Category_of_Building»​
«Area_of_Building»​
«Building_Value»​
Total​
«Total_Value»​

Total Value: «Total_Value»$.
-------

In this case 2, I copy paragraphs
1.1 Customer 1:
- Name: «Name»
- ID card: «ID_card»
- Birthday: «Birthday»
- Address: «Address»
And past its below, then I change ‘1.1 Customer 1’ to ‘1.2 Customer 2’. I use «Next Record» in front of ‘1.2 Customer 2’ three times.

I continue to copy and past paragraph ‘2.1/ Property 1: «CodeProperty»’ two times, then I change to ‘2.2/ Property 2: «CodeProperty»’ and ‘2.3/ Property 3: «CodeProperty»’. I use «Next Record» in front of the paragraphs.

=> Here is the result (case 2)
VALUATION​

Today on 01/04/2014, at New York:

1/ Customer
1.1 Customer 1:
- Name: Name A
- ID card: 123456
- Birthday: 14/01/1980
- Address: Chicago
1.2 Customer 2:
- Name: Name B
- ID card: 234567
- Birthday: 22/04/1982
- Address: New Yorth

2/ Code of Property:
2.1/ Property 1: 01
2.2/ Property 2: 02
2.3/ Property 3: 03

3/ Land
Code
Category
Address
Area
01​
Cultivated land​
district 1, town 1​
51200​
02​
Living land​
district 2, city 2​
1450​
03​
Living land​
district 3, city 2​
2001​

4/ Building

Code
Category
Area
01​
Store 1​
1000​
02​
House 2​
1500​
03​
House 3​
1450​

5/Valuation
Code
Category
Area
Value
01​
Cultivated land​
51200​
67000​
01​
Store 1​
1000​
40000​
02​
Living land​
1450​
84000​
02​
House 2​
1500​
92000​
03​
Living land​
2001​
35000​
03​
House 3​
1450​
54000​
Total​
372000​

Total Value: 372000$.

So, if we have 2 customers and 4 properties, or 3 customers and 4 properties, or n customers and n properties, how we will write code VBA ?
 

Users who are viewing this thread

Back
Top Bottom