Reply
 
Thread Tools Display Modes
  #1   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default DocType Directory changes to Letters

I'm updating an application from 2000 to 2003. The application did a
mailmerge with a doctype of Catalog. I have changed the doctype to
Directory. When I open the word doc manually, it has the properties it
should: doctype=Directory. When I open it programmatically from Access
using VBA, doctype=Letters and the mailmerge doesn't behave as anticipated.
code fragment to open file:
Set doc = app.Documents.Open(Path & "Merge.doc")

merge.MainDocumentType = wdDirectory
doesn't have any affect either.

--
Message posted via http://www.officekb.com
  #2   Report Post  
Peter Jamieson
 
Posts: n/a
Default

Set doc = app.Documents.Open(Path & "Merge.doc")

merge.MainDocumentType = wdDirectory


There seems to be a bit of text missing here, but you need something like:

Set doc = app.Documents.Open(Path & "Merge.doc")
doc.MailMerge.MainDocumentType = wdDirectory

But first you may need to follow the instructions in this article:

http://support.microsoft.com/default...b;en-us;825765

Peter Jamieson

"Don Petersen via OfficeKB.com" wrote in message
...
I'm updating an application from 2000 to 2003. The application did a
mailmerge with a doctype of Catalog. I have changed the doctype to
Directory. When I open the word doc manually, it has the properties it
should: doctype=Directory. When I open it programmatically from Access
using VBA, doctype=Letters and the mailmerge doesn't behave as
anticipated.
code fragment to open file:
Set doc = app.Documents.Open(Path & "Merge.doc")

merge.MainDocumentType = wdDirectory
doesn't have any affect either.

--
Message posted via http://www.officekb.com



  #3   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

Sorry for cutting out a little code:

Set app = CreateObject("Word.Application")
Set merge = app.ActiveDocument.MailMerge
With merge
.MainDocumentType = wdCatalog

should fill in the blanks some.

I tried your suggestion:

doc.MailMerge.MainDocumentType = wdDirectory
and even:
doc.MailMerge.MainDocumentType = wdCatalog

and the type did not change. It is still wdFormLetters.

--
Message posted via http://www.officekb.com
  #4   Report Post  
Peter Jamieson
 
Posts: n/a
Default

I may be missing something, but

immediately after this...

Set app = CreateObject("Word.Application")

no document is open in app, so there is no ActiveDocument, so there is no
MailMerge object for the set merge line. If you are starting from a blank
document, you will probably need at least

app.Documents.Add

and preferably

Dim oDoc as Word.Document
Set oDoc = app.Documents.Add

If you are starting from an existing document you could use

Dim oDoc as Word.Document
Set oDoc = app.Documents.Open("pathname of the .doc")

Peter Jamieson

"Don Petersen via OfficeKB.com" wrote in message
...
Sorry for cutting out a little code:

Set app = CreateObject("Word.Application")
Set merge = app.ActiveDocument.MailMerge
With merge
.MainDocumentType = wdCatalog

should fill in the blanks some.

I tried your suggestion:

doc.MailMerge.MainDocumentType = wdDirectory
and even:
doc.MailMerge.MainDocumentType = wdCatalog

and the type did not change. It is still wdFormLetters.

--
Message posted via http://www.officekb.com



  #5   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

Sorry, I left some code out for brevity's sake. If it weren't there, then I
would have gotten other run-time errors. Here is the full code:

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")
Set merge = app.ActiveDocument.MailMerge
doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
SQLStatement:="Select * From 'Docs';" ' I've tried a number of
syntactic variations on this stmt based on a number of articles.
' These two lines are for another solution suggested by MS in a KBA.
'Connection:="TABLE [Docs]", _
'SubType:=wdMergeSubTypeWord2000
doc.MailMerge.MainDocumentType = wdDirectory
With merge
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute

The type of the document is still Letters. If I open the document manually,
the type is Directory, as I desire.

--
Message posted via http://www.officekb.com


  #6   Report Post  
Peter Jamieson
 
Posts: n/a
Default

OK, I think I suggested

doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs];"

but the ";" should not be there (even though it is normal SQL syntax).

/Normally/, the code I suggested should be enough.

But if that does not work, at the moment I can't see what is happening
here. Unfortunately I'm away next week so may not be able to pursue this
until after that, but here are a few suggestions...

Can you please open the document manually, then use VBA to output the values
of

ActiveDocument.MailMerge.DataSource.Name
ActiveDocument.MailMerge.DataSource.ConnectString
ActiveDocument.MailMerge.DataSource.QueryString

Are you also definitely not seeing the issues associated with the KB article
I mentioned earlier?

Does your database have either password security or user level (workgroup)
security set up?

Another thing to notice is the kind of dialog box that is displayed when
Word tries to open the file - if it has an Options button in the bottom
left, it's an ODBC dialog box, and that would typically mean that Word had
tried using OLEDB and failed, which probably means that the SQL syntax is
wrong.

FWIW,

'Connection:="TABLE [Docs]", _


This syntax in the Connection parameter is only used when you want to
connect using DDE, and is in fact optional as a SQL statement can be
provided in the SQLStatement parameter anyway.

'SubType:=wdMergeSubTypeWord2000


This parameter should only be used if you want to connect using DDE or
ODBC. It forces Word to use the old Word 2000 approach (and Word 2000 did
not support OLEDB).

Peter Jamieson

"Don Petersen via OfficeKB.com" wrote in message
...
Sorry, I left some code out for brevity's sake. If it weren't there, then
I
would have gotten other run-time errors. Here is the full code:

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")
Set merge = app.ActiveDocument.MailMerge
doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
SQLStatement:="Select * From 'Docs';" ' I've tried a number of
syntactic variations on this stmt based on a number of articles.
' These two lines are for another solution suggested by MS in a KBA.
'Connection:="TABLE [Docs]", _
'SubType:=wdMergeSubTypeWord2000
doc.MailMerge.MainDocumentType = wdDirectory
With merge
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute

The type of the document is still Letters. If I open the document
manually,
the type is Directory, as I desire.

--
Message posted via http://www.officekb.com



  #7   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

I removed the ';' at the end of the SQL statement and the connection
appeared to work OK. Microsoft - sheesh!
Thanks. Have a nice trip!

--
Message posted via http://www.officekb.com
  #8   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

There are two issues with this code. One is that there was a prompt for a
table on opening the datasource. That seems to be fixed by removing the ';'
from the SQLStatment clause.

The other problem is that a mailmerge doc of type Directory becomes type
Letters when opened by VBA code in Access.

Are you also definitely not seeing the issues associated with the KB

article
I mentioned earlier?

I do get that behavior. I don't understand the connection between that
behavior and a Letters or Directory datatype.

Does your database have either password security or user level (workgroup)
security set up?

No.

I will work on this:
Can you please open the document manually, then use VBA to output the

values of

ActiveDocument.MailMerge.DataSource.Name
ActiveDocument.MailMerge.DataSource.ConnectStrin g
ActiveDocument.MailMerge.DataSource.QueryStrin g


--
Message posted via http://www.officekb.com
  #9   Report Post  
Peter Jamieson
 
Posts: n/a
Default


I do get that behavior. I don't understand the connection between that
behavior and a Letters or Directory datatype.


The problem is that if you don't have the registry entry described in the KB
article, opendatasource will fail and what happens next will depend on what
error handling you have set up.

Peter Jamieson

"Don Petersen via OfficeKB.com" wrote in message
...
There are two issues with this code. One is that there was a prompt for a
table on opening the datasource. That seems to be fixed by removing the
';'
from the SQLStatment clause.

The other problem is that a mailmerge doc of type Directory becomes type
Letters when opened by VBA code in Access.

Are you also definitely not seeing the issues associated with the KB

article
I mentioned earlier?

I do get that behavior. I don't understand the connection between that
behavior and a Letters or Directory datatype.

Does your database have either password security or user level
(workgroup)
security set up?

No.

I will work on this:
Can you please open the document manually, then use VBA to output the

values of

ActiveDocument.MailMerge.DataSource.Name
ActiveDocument.MailMerge.DataSource.ConnectStri ng
ActiveDocument.MailMerge.DataSource.QueryStri ng


--
Message posted via http://www.officekb.com



  #10   Report Post  
Peter Jamieson
 
Posts: n/a
Default

BTW, I meant to say before that the code you posted is mixing objects a bit
(once you've set up the doc object variable it's probably better to use it
rather than refer to ActiveDocument again). It may not make any difference
in practice but...

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")


IMO at this point it might be better to use either something like

With doc.MailMerge
.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs]"
.MainDocumentType = wdDirectory
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute
End With

or

Set merge = doc.MailMerge
with merge
.OpenDataSource _
Name:=Path & "IPdb.mdb", _
SQLStatement:="Select * From [Docs]"
.MainDocumentType = wdDirectory
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute
end with


"Don Petersen via OfficeKB.com" wrote in message
...
Sorry, I left some code out for brevity's sake. If it weren't there, then
I
would have gotten other run-time errors. Here is the full code:

Set app = CreateObject("Word.Application")
app.Visible = True
Set doc = app.Documents.Open(Path & "CatMergeUS.doc")
Set merge = app.ActiveDocument.MailMerge
doc.MailMerge.OpenDataSource _
Name:=Path & "IPdb.mdb", _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
SQLStatement:="Select * From 'Docs';" ' I've tried a number of
syntactic variations on this stmt based on a number of articles.
' These two lines are for another solution suggested by MS in a KBA.
'Connection:="TABLE [Docs]", _
'SubType:=wdMergeSubTypeWord2000
doc.MailMerge.MainDocumentType = wdDirectory
With merge
.Destination = wdSendToNewDocument
.MainDocumentType = wdDirectory
.Execute

The type of the document is still Letters. If I open the document
manually,
the type is Directory, as I desire.

--
Message posted via http://www.officekb.com





  #11   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

Hi,
Thanks for the response. I looked at the KB article again. It suggests
lowering security. Don't think I want to do that. I get the prompt when I
open the doc manually, but not from VB. The datasource is getting opened. I
get the correct info, just the wrong format (Letters vs Catalog).

I tried both your code fragments and neither was successful at changing the
MainDocumentType from FormLetters to Catalog / Directory

I opened the doc manually and got:
Debug.Print ActiveDocument.MailMerge.DataSource.Name
E:\mii\ipdb\pluto\IPdb.mdb
Debug.Print ActiveDocument.MailMerge.DataSource.ConnectString
DSN=MS Access Database;DBQ=E:\mii\ipdb\pluto\IPdb.mdb;DriverId=2 5;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;
Debug.Print ActiveDocument.MailMerge.DataSource.QueryString
SELECT * FROM `Docs` WHERE ((`Class` = 'All') AND (`Type` = 'US'))
Debug.Print ActiveDocument.MailMerge.MainDocumentType
3 (wdCatalog / wdDirectory)

This all looks pretty good to me. Any other ideas? Thanks.

--
Message posted via http://www.officekb.com
  #12   Report Post  
Don Petersen via OfficeKB.com
 
Posts: n/a
Default

I have a solution!! It's not pretty, but it works. I was stepping through
the code and noticed that when setting MainDocumentType to wdCatalog or
wdDirectory, MainDocumentType changed from NotaMergeDoc to wdFormLetters!!
So, I changed the code to set MainDocumentType to '3'. It showed as
wdDirectory and the merge ran just as desired.
Looks like a big fat M$ bug to me!! What a waste of time.

--
Message posted via http://www.officekb.com
  #13   Report Post  
Peter Jamieson
 
Posts: n/a
Default

Hi,

Looks like a big fat M$ bug to me!! What a waste of time.


Thanks for posting this.

Peter Jamieson

"wdCatalog" or "wdDirectory" as a built-in constant, is treating it as a
variable, and using
"Don Petersen via OfficeKB.com" wrote in message
...
I have a solution!! It's not pretty, but it works. I was stepping through
the code and noticed that when setting MainDocumentType to wdCatalog or
wdDirectory, MainDocumentType changed from NotaMergeDoc to wdFormLetters!!
So, I changed the code to set MainDocumentType to '3'. It showed as
wdDirectory and the merge ran just as desired.
Looks like a big fat M$ bug to me!! What a waste of time.

--
Message posted via http://www.officekb.com



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu, .Dot, Startup directory, etc Bruce the Word Questioner Microsoft Word Help 3 February 3rd 05 01:59 PM
Not all the checked names are merged into letters Bea Mailmerge 1 February 1st 05 02:00 AM
Mail Merge is creating blank pages between form letters JW Mailmerge 1 January 25th 05 11:54 PM
Saving files from a template to a directory csustew Microsoft Word Help 1 January 10th 05 11:12 PM
Letters gets changed when copied from PDF Document Ponnurangam Microsoft Word Help 1 November 24th 04 04:39 PM


All times are GMT +1. The time now is 10:30 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"