How to parse the merge fields in a word document?????

sophie.ch1
Member Posts: 2
Hi,
I want to automatically create a word document which will contain some fields from customer table e.g name, contact, address etc. But, i want the user to be able to choose these merge fields in the word document. For example, some users may want to have name, address and contact fields, where some others may just want to have name and address fields only.
I wrote the following code:
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := Contact;
wdRange := wdApp.ActiveDocument.Fields.Item(2).Result;
wdRange.Text := Name;
wdRange := wdApp.ActiveDocument.Fields.Item(3).Result;
wdRange.Text := Address;
but the problem is that when the user inserts only 2 merge fields in the document (because i do not want it to be a fixed document) i get this error:
"The call to member Item failed. Microsoft returned the following message: The requested member of the collection does not exist".
So, i have to parse the fields in the document and then try to transfer the data from the customer table into the word document. Does anyone wrote some code about this or does anyone have an idea of how to this? I 'm new in Navision and unfortunately i don't have any ideas.
Thanks in advance,
Sophie[/code]
I want to automatically create a word document which will contain some fields from customer table e.g name, contact, address etc. But, i want the user to be able to choose these merge fields in the word document. For example, some users may want to have name, address and contact fields, where some others may just want to have name and address fields only.
I wrote the following code:
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := Contact;
wdRange := wdApp.ActiveDocument.Fields.Item(2).Result;
wdRange.Text := Name;
wdRange := wdApp.ActiveDocument.Fields.Item(3).Result;
wdRange.Text := Address;
but the problem is that when the user inserts only 2 merge fields in the document (because i do not want it to be a fixed document) i get this error:
"The call to member Item failed. Microsoft returned the following message: The requested member of the collection does not exist".
So, i have to parse the fields in the document and then try to transfer the data from the customer table into the word document. Does anyone wrote some code about this or does anyone have an idea of how to this? I 'm new in Navision and unfortunately i don't have any ideas.
Thanks in advance,
Sophie[/code]
Sophie Christophorou
0
Comments
-
Hi Sophie,
Perhaps you could look at codeunit 5054 WordManagement and look at the following functions:
ExecuteMerge
ShowMergedDocument
CreateHeader
Maybe this helps.
Regards
Albert0 -
You shoud count the number of members in Fields collection before. I forgot the axact property/function, but you can find this in VBA help.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions