Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Manipulate Word document with VBA

Posted on 2004-10-05
13
Medium Priority
?
212 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

618 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