MailMerge OpenDataSource CU680
nav4all
Member Posts: 3
Hi
To overcome the 64 field limit in HTM file MailMerge funcionality I tried this in a vb script and it worked exactly as it should.
Problems start when I want to implement it in CU680, NAV don't want my parameters..
First, I changed the extension on the merge file to HTML. Then Word understand nothing and think it's an external datasource, which is good, no 64 field boundary.
Here is vbs :
Dim wrdApp
Dim wrdDoc
Dim dsName
Dim FileName
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
dsname = "C:\NAV\MBS KM\MAILMERGE\MergeSource.HTML"
FileName = "C:\NAV\MBS KM\MAILMERGE\MergeTarget.DOC"
wrdDoc.MailMerge.OpenDataSource _
dsName, _
false , _
false , _
true , _
false , _
0 , _
"" , _
"" , _
0 , _
"" , _
"" , _
"" , _
"SELECT * FROM `Table`" , _
"", _
true, _
1
wrdDoc.SaveAs FileName, 0
wrdDoc.ActiveWindow.Caption = "VBS Test"
wrdDoc.Saved = TRUE
wrdApp.Visible = TRUE
Set wrdDoc = Nothing
Set wrdApp = Nothing
When I try to change :
wrdDoc.MailMerge.OpenDataSource(MergeFileName,ParamInt);
in CU680
to:
MergeFileName := 'C:\NAV\MBS KM\MAILMERGE\MergeSource.HTML';
dsName := MergeFileName;
dsConfirmConversions := FALSE;
dsReadOnly := FALSE;
dsLinkToSource := TRUE;
dsAddToRecentFiles := FALSE;
dsPasswordDocument := 0;
dsPasswordTemplate := '';
dsWritePasswordDocument := 0;
dsWritePasswordTemplate := 0;
dsRevert := FALSE;
dsFormat := 7;
dsConnection := '';
dsSQLStatement := 'SELECT * FROM ''TABLE''';
dsSQLStatement1 := '';
dsOpenExclusive := 0;
dsSubType := 0;
wrdDoc.MailMerge.OpenDataSource
(
dsName,
dsConfirmConversions,
dsReadOnly,
dsLinkToSource,
dsAddToRecentFiles,
dsPasswordDocument,
dsPasswordTemplate,
dsWritePasswordDocument,
dsWritePasswordTemplate,
dsRevert,
dsFormat,
dsConnection,
dsSQLStatement,
dsSQLStatement1,
dsOpenExclusive,
dsSubType
);
Then it will not run, error : One or more of the arguments could not be coerced.
All variables is declared Variant and assigned an value, OpenDataSource obviously don't like Byvalue..
Anybody out there who have any ideas how to solve this ?
To overcome the 64 field limit in HTM file MailMerge funcionality I tried this in a vb script and it worked exactly as it should.
Problems start when I want to implement it in CU680, NAV don't want my parameters..
First, I changed the extension on the merge file to HTML. Then Word understand nothing and think it's an external datasource, which is good, no 64 field boundary.
Here is vbs :
Dim wrdApp
Dim wrdDoc
Dim dsName
Dim FileName
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
dsname = "C:\NAV\MBS KM\MAILMERGE\MergeSource.HTML"
FileName = "C:\NAV\MBS KM\MAILMERGE\MergeTarget.DOC"
wrdDoc.MailMerge.OpenDataSource _
dsName, _
false , _
false , _
true , _
false , _
0 , _
"" , _
"" , _
0 , _
"" , _
"" , _
"" , _
"SELECT * FROM `Table`" , _
"", _
true, _
1
wrdDoc.SaveAs FileName, 0
wrdDoc.ActiveWindow.Caption = "VBS Test"
wrdDoc.Saved = TRUE
wrdApp.Visible = TRUE
Set wrdDoc = Nothing
Set wrdApp = Nothing
When I try to change :
wrdDoc.MailMerge.OpenDataSource(MergeFileName,ParamInt);
in CU680
to:
MergeFileName := 'C:\NAV\MBS KM\MAILMERGE\MergeSource.HTML';
dsName := MergeFileName;
dsConfirmConversions := FALSE;
dsReadOnly := FALSE;
dsLinkToSource := TRUE;
dsAddToRecentFiles := FALSE;
dsPasswordDocument := 0;
dsPasswordTemplate := '';
dsWritePasswordDocument := 0;
dsWritePasswordTemplate := 0;
dsRevert := FALSE;
dsFormat := 7;
dsConnection := '';
dsSQLStatement := 'SELECT * FROM ''TABLE''';
dsSQLStatement1 := '';
dsOpenExclusive := 0;
dsSubType := 0;
wrdDoc.MailMerge.OpenDataSource
(
dsName,
dsConfirmConversions,
dsReadOnly,
dsLinkToSource,
dsAddToRecentFiles,
dsPasswordDocument,
dsPasswordTemplate,
dsWritePasswordDocument,
dsWritePasswordTemplate,
dsRevert,
dsFormat,
dsConnection,
dsSQLStatement,
dsSQLStatement1,
dsOpenExclusive,
dsSubType
);
Then it will not run, error : One or more of the arguments could not be coerced.
All variables is declared Variant and assigned an value, OpenDataSource obviously don't like Byvalue..
Anybody out there who have any ideas how to solve this ?
0
Comments
-
The solution was very simple..when you find it...
In CU681 change the following in function ConstMergeSourceFileName
//FileName := "3TierAutoMgt".EnvironFileName(Text002 + DocNo + '.','HTM');
FileName := "3TierAutoMgt".EnvironFileName(Text002 + DocNo + '.','HTML');
In CU680, functions CreateMailMergeDocuments and OpenmailmergeDocuments
Move the following statement before wrdDoc.MailMerge.OpenDataSource(MergeFileName,ParamInt);
wrdApp.Visible := TRUE;
As far as I know there is no way to get rid of the "select table" dialog box when you use HTML file as MergeSource but we can live with that, it's not an daily procedure.
Enjoy0 -
hi,
Thanks for sharing your workingprocess. it helps me alot.
from my perspective I changed the following to get it work:
- i changed the DataType of the variables to this:dsConfirmConversions [Boolean] dsReadOnly [Boolean] dsLinkToSource [Boolean] dsAddToRecentFiles [Boolean] dsPasswordDocument [Text30] dasPasswordTEmplate [Text30] dsWritePasswordDocument [Text30] dsWirtePasswordTemplate [Text30] dsRevert [Boolean] dsConnect [Text30] dsSQLStatement [Text30] dsSQLStatement1 [Text30] dsOpenExclusive [Boolean] dsSubType [Integer] dsFilename [Text260] dsFormat [Integer]
- and i changed the order of the parameters in OpenDataSource to this:wrdDocument.MailMerge.OpenDataSource(dsFilename, dsFormat, dsConfirmConversions, dsReadOnly, dsLinkToSource, dsAddToRecentFiles, dsPasswordDocument, dasPasswordTEmplate, dsRevert, dsWritePasswordDocument, dsWirtePasswordTemplate, dsConnect, dsSQLStatement, dsSQLStatement1, dsOpenExclusive, dsSubType);
- and I changed the initvalues for the parameters to this:dsConfirmConversions := FALSE; dsReadOnly := FALSE; dsLinkToSource := TRUE; dsAddToRecentFiles := FALSE; dsPasswordDocument := ''; dasPasswordTEmplate := ''; dsWritePasswordDocument := ''; dsWirtePasswordTemplate := ''; dsRevert := FALSE; dsConnect := ''; dsSQLStatement := 'SELECT * FROM `Table`'; dsSQLStatement1 := ''; dsOpenExclusive := FALSE; dsSubType := 0; dsFilename := 'C:\yourfile.html'; dsFormat := 7;
- it is really important to change the extension of the file from .HTM to .HTML
- and I think it depends on the value of "dsSQLSatement" that Word will not show any Dialog while opening
With the described changes the MailMerge works fine for me.
I tested with 170 fields (I think till 255 will be possible). I will go on a productive system soon.
Best,
Hannes0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions