Group:  Microsoft Word ยป microsoft.public.word.mailmerge.fields
Thread: Losing MainDocumentType on Open()

Geek News

Losing MainDocumentType on Open()
Jerry 11/24/2008 6:18:02 PM
Hey guys, I have a mail merge document that is set to Directory for the Main
Document Type. If I close it and manually reopen it, it stays as a
"Directory" document, but if I open it through automation (i.e.
oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do the
Open() command and then it gets set to 0 once you call the OpenDataSource().

How can I open the document through automation and keep the document type
that the user originally saved it with?


Thanks for your help,

Jerry
Re: Losing MainDocumentType on Open()
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 11/24/2008 7:26:20 PM
Can you show us the complete code that you are using.

--
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

"Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
[Quoted Text]
> Hey guys, I have a mail merge document that is set to Directory for the
> Main
> Document Type. If I close it and manually reopen it, it stays as a
> "Directory" document, but if I open it through automation (i.e.
> oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
> oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do the
> Open() command and then it gets set to 0 once you call the
> OpenDataSource().
>
> How can I open the document through automation and keep the document type
> that the user originally saved it with?
>
>
> Thanks for your help,
>
> Jerry


Re: Losing MainDocumentType on Open()
Jerry 11/24/2008 7:58:03 PM
Hi Doug, here it is (this is done through Visual FoxPro):

cExisitngMailMergeTemplate="C:\Path\SomeDocument.doc"
cMailMergeDataFile="C:\Path\SomeData.csv"

oWord=CREATEOBJECT("Word.Application")
oWord.Documents.OPEN(cExistingMailMergeTemplate)
oWord.ActiveDocument.MailMerge.OpenDataSource(cMailMergeDataFile)
oWord.Visible=.T.

As soon as you do the OPEN() command is when the MainDocumentType is set to
-1 and then it gets set to 0 after you call OpenDataSource()


Thanks,

Jerry

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Can you show us the complete code that you are using.
>
> --
> 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
>
> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
> > Hey guys, I have a mail merge document that is set to Directory for the
> > Main
> > Document Type. If I close it and manually reopen it, it stays as a
> > "Directory" document, but if I open it through automation (i.e.
> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do the
> > Open() command and then it gets set to 0 once you call the
> > OpenDataSource().
> >
> > How can I open the document through automation and keep the document type
> > that the user originally saved it with?
> >
> >
> > Thanks for your help,
> >
> > Jerry
>
>
>
Re: Losing MainDocumentType on Open()
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 11/24/2008 10:26:05 PM
Hi Jerry,

Are you really sure that the document that you are opening is saved as a
Directory type mail merge main document?

The MailMerge.MainDocumentType of -1 indicates that it is not. Using code
to attach a data source will set that .MainDocumentType to 0 (= Letter type)
if the type has not been set otherwise.

I cannot replicate the issue of a document that was saved as a Directory
being re-set to a normal word document (MailMergeType = -1) when using the
Documents.Open command.

When I use

Dim doc As Document
Set doc = Documents.Open("C:\documents\directory.doc")
MsgBox doc.MailMerge.MainDocumentType

to open a directory type mail merge main document, 3 is displayed in the
message box.

As a work around, include the following command to explicity set the
document that you are opening to a directory type mail merge main document.

oWord.ActiveDocument.MailMerge.MainDocumentType = 3

--
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

"Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
news:3104C573-09CB-4AD0-B7D0-D2CE10A3F2A4[ at ]microsoft.com...
[Quoted Text]
> Hi Doug, here it is (this is done through Visual FoxPro):
>
> cExisitngMailMergeTemplate="C:\Path\SomeDocument.doc"
> cMailMergeDataFile="C:\Path\SomeData.csv"
>
> oWord=CREATEOBJECT("Word.Application")
> oWord.Documents.OPEN(cExistingMailMergeTemplate)
> oWord.ActiveDocument.MailMerge.OpenDataSource(cMailMergeDataFile)
> oWord.Visible=.T.
>
> As soon as you do the OPEN() command is when the MainDocumentType is set
> to
> -1 and then it gets set to 0 after you call OpenDataSource()
>
>
> Thanks,
>
> Jerry
>
> "Doug Robbins - Word MVP" wrote:
>
>> Can you show us the complete code that you are using.
>>
>> --
>> 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
>>
>> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
>> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
>> > Hey guys, I have a mail merge document that is set to Directory for the
>> > Main
>> > Document Type. If I close it and manually reopen it, it stays as a
>> > "Directory" document, but if I open it through automation (i.e.
>> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
>> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do
>> > the
>> > Open() command and then it gets set to 0 once you call the
>> > OpenDataSource().
>> >
>> > How can I open the document through automation and keep the document
>> > type
>> > that the user originally saved it with?
>> >
>> >
>> > Thanks for your help,
>> >
>> > Jerry
>>
>>
>>


Re: Losing MainDocumentType on Open()
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 11/25/2008 8:52:55 AM
You probably need to make the registry change described in the following KB
article:

http://support.microsoft.com/kb/825765/en-us

If you don't, when you open the Word document in code, the data source is
diconnected and the document that is supposed to be a Mail merge Main
Document becomes a Normal Word Document.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
[Quoted Text]
> Hey guys, I have a mail merge document that is set to Directory for the
> Main
> Document Type. If I close it and manually reopen it, it stays as a
> "Directory" document, but if I open it through automation (i.e.
> oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
> oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do the
> Open() command and then it gets set to 0 once you call the
> OpenDataSource().
>
> How can I open the document through automation and keep the document type
> that the user originally saved it with?
>
>
> Thanks for your help,
>
> Jerry

Re: Losing MainDocumentType on Open()
Jerry 11/26/2008 5:26:09 PM
Hi Doug, yes, I'm sure that the document type is set because when I manually
open it, it still shows as a Directory type.

Is there anyway to get the documenttype before calling the Open() method?


"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Hi Jerry,
>
> Are you really sure that the document that you are opening is saved as a
> Directory type mail merge main document?
>
> The MailMerge.MainDocumentType of -1 indicates that it is not. Using code
> to attach a data source will set that .MainDocumentType to 0 (= Letter type)
> if the type has not been set otherwise.
>
> I cannot replicate the issue of a document that was saved as a Directory
> being re-set to a normal word document (MailMergeType = -1) when using the
> Documents.Open command.
>
> When I use
>
> Dim doc As Document
> Set doc = Documents.Open("C:\documents\directory.doc")
> MsgBox doc.MailMerge.MainDocumentType
>
> to open a directory type mail merge main document, 3 is displayed in the
> message box.
>
> As a work around, include the following command to explicity set the
> document that you are opening to a directory type mail merge main document.
>
> oWord.ActiveDocument.MailMerge.MainDocumentType = 3
>
> --
> 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
>
> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
> news:3104C573-09CB-4AD0-B7D0-D2CE10A3F2A4[ at ]microsoft.com...
> > Hi Doug, here it is (this is done through Visual FoxPro):
> >
> > cExisitngMailMergeTemplate="C:\Path\SomeDocument.doc"
> > cMailMergeDataFile="C:\Path\SomeData.csv"
> >
> > oWord=CREATEOBJECT("Word.Application")
> > oWord.Documents.OPEN(cExistingMailMergeTemplate)
> > oWord.ActiveDocument.MailMerge.OpenDataSource(cMailMergeDataFile)
> > oWord.Visible=.T.
> >
> > As soon as you do the OPEN() command is when the MainDocumentType is set
> > to
> > -1 and then it gets set to 0 after you call OpenDataSource()
> >
> >
> > Thanks,
> >
> > Jerry
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> Can you show us the complete code that you are using.
> >>
> >> --
> >> 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
> >>
> >> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
> >> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
> >> > Hey guys, I have a mail merge document that is set to Directory for the
> >> > Main
> >> > Document Type. If I close it and manually reopen it, it stays as a
> >> > "Directory" document, but if I open it through automation (i.e.
> >> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
> >> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do
> >> > the
> >> > Open() command and then it gets set to 0 once you call the
> >> > OpenDataSource().
> >> >
> >> > How can I open the document through automation and keep the document
> >> > type
> >> > that the user originally saved it with?
> >> >
> >> >
> >> > Thanks for your help,
> >> >
> >> > Jerry
> >>
> >>
> >>
>
>
>
Re: Losing MainDocumentType on Open()
Jerry 11/26/2008 5:34:01 PM
Hi Peter, this does seem to work, but I'm not sure it is a viable solution
for me. Is there any other work a rounds for this?


Thanks,

Jerry

"Peter Jamieson" wrote:

[Quoted Text]
> You probably need to make the registry change described in the following KB
> article:
>
> http://support.microsoft.com/kb/825765/en-us
>
> If you don't, when you open the Word document in code, the data source is
> diconnected and the document that is supposed to be a Mail merge Main
> Document becomes a Normal Word Document.
>
> --
> Peter Jamieson
> http://tips.pjmsn.me.uk
>
> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
> > Hey guys, I have a mail merge document that is set to Directory for the
> > Main
> > Document Type. If I close it and manually reopen it, it stays as a
> > "Directory" document, but if I open it through automation (i.e.
> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do the
> > Open() command and then it gets set to 0 once you call the
> > OpenDataSource().
> >
> > How can I open the document through automation and keep the document type
> > that the user originally saved it with?
> >
> >
> > Thanks for your help,
> >
> > Jerry
>
>
Re: Losing MainDocumentType on Open()
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 11/26/2008 7:29:22 PM
The work around is either to follow the instructions in the link that Peter
provided or include the following command to explicity set the
document that you are opening to a directory type mail merge main document.

oWord.ActiveDocument.MailMerge.MainDocumentType = 3



--
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

"Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
news:DCDD73BE-0161-4E62-9395-07123EE2D91C[ at ]microsoft.com...
[Quoted Text]
> Hi Doug, yes, I'm sure that the document type is set because when I
> manually
> open it, it still shows as a Directory type.
>
> Is there anyway to get the documenttype before calling the Open() method?
>
>
> "Doug Robbins - Word MVP" wrote:
>
>> Hi Jerry,
>>
>> Are you really sure that the document that you are opening is saved as a
>> Directory type mail merge main document?
>>
>> The MailMerge.MainDocumentType of -1 indicates that it is not. Using
>> code
>> to attach a data source will set that .MainDocumentType to 0 (= Letter
>> type)
>> if the type has not been set otherwise.
>>
>> I cannot replicate the issue of a document that was saved as a Directory
>> being re-set to a normal word document (MailMergeType = -1) when using
>> the
>> Documents.Open command.
>>
>> When I use
>>
>> Dim doc As Document
>> Set doc = Documents.Open("C:\documents\directory.doc")
>> MsgBox doc.MailMerge.MainDocumentType
>>
>> to open a directory type mail merge main document, 3 is displayed in the
>> message box.
>>
>> As a work around, include the following command to explicity set the
>> document that you are opening to a directory type mail merge main
>> document.
>>
>> oWord.ActiveDocument.MailMerge.MainDocumentType = 3
>>
>> --
>> 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
>>
>> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
>> news:3104C573-09CB-4AD0-B7D0-D2CE10A3F2A4[ at ]microsoft.com...
>> > Hi Doug, here it is (this is done through Visual FoxPro):
>> >
>> > cExisitngMailMergeTemplate="C:\Path\SomeDocument.doc"
>> > cMailMergeDataFile="C:\Path\SomeData.csv"
>> >
>> > oWord=CREATEOBJECT("Word.Application")
>> > oWord.Documents.OPEN(cExistingMailMergeTemplate)
>> > oWord.ActiveDocument.MailMerge.OpenDataSource(cMailMergeDataFile)
>> > oWord.Visible=.T.
>> >
>> > As soon as you do the OPEN() command is when the MainDocumentType is
>> > set
>> > to
>> > -1 and then it gets set to 0 after you call OpenDataSource()
>> >
>> >
>> > Thanks,
>> >
>> > Jerry
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> Can you show us the complete code that you are using.
>> >>
>> >> --
>> >> 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
>> >>
>> >> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
>> >> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
>> >> > Hey guys, I have a mail merge document that is set to Directory for
>> >> > the
>> >> > Main
>> >> > Document Type. If I close it and manually reopen it, it stays as a
>> >> > "Directory" document, but if I open it through automation (i.e.
>> >> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc"))
>> >> > the
>> >> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you
>> >> > do
>> >> > the
>> >> > Open() command and then it gets set to 0 once you call the
>> >> > OpenDataSource().
>> >> >
>> >> > How can I open the document through automation and keep the document
>> >> > type
>> >> > that the user originally saved it with?
>> >> >
>> >> >
>> >> > Thanks for your help,
>> >> >
>> >> > Jerry
>> >>
>> >>
>> >>
>>
>>
>>


Re: Losing MainDocumentType on Open()
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 11/26/2008 11:10:03 PM
[Quoted Text]
> Is there any other work a rounds for this?

As far as I know the only alternative based on Word's built-in Mail merge
is to have a mail merge main document that does not have a SQL command
stored in it. That possibility was explored in this group a year or two ago
but
a. it involved saving the Word document in rtf format and patching the rtf
code to remove the SQL statement
b. it could only work with a data source where Word would correctly
regenerate the required SQL statement
c. I suspect that one of the later SPs has blocked that particular loophole

Precisely why it more insecure for a document to connect to a data source
than to have a situation where you have no alternative but to implement this
registry patch is not clear to me.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
news:A4C8FBAA-2C08-4F0B-BDB9-A750E7CC62C3[ at ]microsoft.com...
> Hi Peter, this does seem to work, but I'm not sure it is a viable solution
> for me. Is there any other work a rounds for this?
>
>
> Thanks,
>
> Jerry
>
> "Peter Jamieson" wrote:
>
>> You probably need to make the registry change described in the following
>> KB
>> article:
>>
>> http://support.microsoft.com/kb/825765/en-us
>>
>> If you don't, when you open the Word document in code, the data source is
>> diconnected and the document that is supposed to be a Mail merge Main
>> Document becomes a Normal Word Document.
>>
>> --
>> Peter Jamieson
>> http://tips.pjmsn.me.uk
>>
>> "Jerry" <Jerry[ at ]discussions.microsoft.com> wrote in message
>> news:44F91610-D88A-4274-9B8F-6D2AC21AE765[ at ]microsoft.com...
>> > Hey guys, I have a mail merge document that is set to Directory for the
>> > Main
>> > Document Type. If I close it and manually reopen it, it stays as a
>> > "Directory" document, but if I open it through automation (i.e.
>> > oWord.Documents.Open("C:\SomeDirectory\SomeDirectoryDocument.doc")) the
>> > oWord.ActiveDocument.MailMerge.MainDocumentType = -1 as soon as you do
>> > the
>> > Open() command and then it gets set to 0 once you call the
>> > OpenDataSource().
>> >
>> > How can I open the document through automation and keep the document
>> > type
>> > that the user originally saved it with?
>> >
>> >
>> > Thanks for your help,
>> >
>> > Jerry
>>
>>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net