Solved

Manipulate Word document with VBA

Posted on 2004-10-05
13
201 Views
Last Modified: 2008-03-04
I use the following code to export a report to a bookmarked location in a Word document. This works fine when running from an mbd but causes Access to crash when run from a runtime file (with the *send error report* message) after compling and formatting the Word document .

Has anyone any ideas?              

DoCmd.OutputTo acOutputReport, "rptFF", acFormatRTF, "C:\Program Files\JA\JOBSTemp\FFletter.doc"

Dim objWord As Word.Application
If objWord Is Nothing Then
   Set objWord = New Word.Application
   objWord.Visible = True
End If
     
With objWord
  .Documents.Add (mTemplatePath & "JOBSletter.dot")
  .Selection.Goto What:=wdGoToBookmark, Name:="DocumentInsert"
  .Selection.InsertFile FileName:="C:\Program Files\JA\JOBSTemp\FFletter.doc"
  Refresh
End With
Set objWord = Nothing
0
Comment
Question by:cmhcyc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 12226832
check this link

Use Automation to Find a Location in a Word Document in Access
http://support.microsoft.com/?kbid=210032
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 12227763
you should close the word object with

objWord.Close

before freeing the memory with the set nothing statement
0
 

Author Comment

by:cmhcyc
ID: 12228250
Hi Capricorn,

Thanks for the link. The code there is fairly similar to that which I am using and I also tried using the MS Word 9.0 Object Library and the MS Word 10.00 Object Library too.

All code runs fine when run as an mdb but still crashes out when run as a runtime module :((

akoster - thanks for your comment - I assume that you mean objWord.activedocument.close? Only I cannot enter objWord.Close....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:ALaRiva
ID: 12230449
Is there an error when it crashes?

Is it crashing on your computer or another computer?

HTH

-Anthony
0
 

Author Comment

by:cmhcyc
ID: 12231110
Hi Anthony,

No, the only message is the *send error report* and then Access closes to the desktop.

This happens on both the development machine and the one target machine that I have tested.
0
 

Author Comment

by:cmhcyc
ID: 12236133
Hi All,

I have narrowed the problem down a bit.

The code posted above creates a file FFLetter.doc which is then inserted into a new Word document.

This works fine when run as an mdb but crashes the runtime distribution.

BUT if I do not create FFLetter.doc but just leave a copy of the .doc in the appropriate folder, the routine runs fine!

I guess that it must be something to do with the need to close or otherwisethe FFLetter.doc before inserting it into the new Word document.

Any ideas?
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 12236815
Don't know for sure if this could be the problem,

have you checked that the export process generating the ffletter.doc file actually pauses the macro execution until it is finished ?

when this is not the case your problem comes to word trying to include a file which is open.
try adding a delay of 30 seconds and find out if the problem stays :

wait_time = timer + 30
while timer < wait_time
   doevents
wend
0
 

Author Comment

by:cmhcyc
ID: 12237299
Hi akoster,

Thanks - it just takes 30secs longer to crash :((
0
 

Author Comment

by:cmhcyc
ID: 12257250
Just noticed that *pop up* was ticked in properties of the report that is used for the OutputTo function. Turning this off allows the procedure to run fine in runtime - but I am at a loss to understand why it would run ok from the mdb!

Thanks for all your help out there!
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 12257726
maybe the runtime doesn't support popups, strange...
0
 

Author Comment

by:cmhcyc
ID: 12257953
...infuriating not seeing the wood for the trees - must have spent a good 2 days on this!
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12898232
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question