Solved

Manipulate Word document with VBA

Posted on 2004-10-05
13
193 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
13 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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:akoster
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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 19

Expert Comment

by:akoster
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:akoster
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now