-----Original Message-----
Dirk,
Well, you are quite correct in your evaluation of the
situation. And by the way, it is Word 2002 not 2003.
I am back now to trying to make Word 2002 be more
consistant. What actually started the whole thing, is
that I was preparing to do a presentation on Automation
using PowerPoint. I wanted to have a button on a slide
that would open one of my existing applications that
merges information to one of several chosen Word
documents. Well when I attempted to use it in this manner
I started getting these strange results and it has just
escalated from there.
Right now I am back to just trying to get a stable
environment where I can demo some things to some
potential clients. When I start up my Access application
which I have now converted to Access 2002, it starts with
no problem. When I attempt to open the Word document it
may or may not complete the task. It will always open an
instance of Word, but may not open the document. (This
never happened using Word 97, thus the attempt to revert
back to 97). In any event if I try the same document
again, I get the message to the effect: "The document did
not load correctly and a serious error occurred." If I
continue, it may or may not load the document. If I try
it again (third time) it will present another message
about opening the document and when I confirm that
message, the document will usually open. This
inconsistancy has just about driven me over the edge.
I have just been testing again after using the following
statements and seem to have a little better results, but
I am still concerned about looking like a fool in front
of my potential clients.
On Error GoTo CreateWordApp
Set wordApp = GetObject(, "Word.Application")
strDocName = "D:\FullPath\MergeDocName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)
With wordApp
' Make the application visible
.Visible = True
' Move to each bookmark and insert text from the form
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Me![Co-Name]))
.ActiveDocument.Bookmarks("Contact").Select
.Selection.Text = (CStr(Me![frmContacts].Form!
[ContactName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Me![Mail-Address1]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Me![Mail-City]))
.ActiveDocument.Bookmarks("ST").Select
.Selection.Text = (CStr(Me![Mail-State]))
.ActiveDocument.Bookmarks("Zip").Select
.Selection.Text = (CStr(Me![Mail-Zip]))
.ActiveDocument.Bookmarks("Greeting").Select
.Selection.Text = (CStr(fName))
End With
wordApp.Visible = True
wordApp.Windows(wordApp.Windows.Count).Activate
' AppActivate "Microsoft Word"
wordApp.Activate
wordApp.WindowState = 0 'wdWindowStateRestore
CreateWordApp:
Set wordApp = CreateObject("Word.Application")
Resume Next
Any other observations you may have, or suggestions would
be appreciated.
I'm no expert on Word, Byron, so you may want to take your questions to
one of the Word newsgroups. I do see an error in the code as posted,
though: there is nothing to stop the code from falling through to the
CreateWordApp logic, and *any* error is also going to transfer control
to that point, even after you've successfully gotten yourself a Word
application object. You may want to do something like this:
'----- start of revised code -----
Sub MakeWordDoc()
' Get existing Word application or create a new one if necessary.
On Error GoTo CreateWordApp ' special error handler
Set wordApp = GetObject(, "Word.Application")
On Error GoTo NormalErrorHandler ' back to normal
' ... body of code goes here ...
Exit_Point:
Set wordApp = Nothing
Exit Sub
CreateWordApp:
' Control comes here if GetObject fails.
Set wordApp = CreateObject("Word.Application")
Resume Next
NormalErrorHandler:
' Control comes here on any other error.
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End Sub
'----- end of revised code -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
.