Solved

Create Word Doc from Access Report, not rtf

Posted on 2008-06-13
5
1,960 Views
Last Modified: 2013-11-28
I wish to export a report to a Word doc. I know the formatting won't export, thats fine.
Here's my code:
  stCriteria = "Tran_ID = " & lTranID
   stReport = "rptFleet_Deletion"
   stPath = "c:\Fleet_Deletion.Doc"
   DoCmd.OpenReport stReport, acViewPreview, , stCriteria, acHidden
   DoCmd.OutputTo acOutputReport, stReport, acFormatRTF, stPath, True
   DoCmd.Close acReport, stReport

I'm cheating to an extent, in that I'm actually creating an rtf file, but calling it .Doc
Seems to work ok on my PC, but I'd like to be sure before I distribute.
Will this cause problems on any PCs? That is, I don't want users to get a warning about the format being rtf or somesuch.
Thanks

0
Comment
Question by:jdhackett
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Word cann open an .rtf or a .doc file. There is no need to give it the wrong extension. Once open it can be saved back in either format.
0
 
LVL 1

Author Comment

by:jdhackett
Comment Utility
I don't want to confuse users and ask them to save it as a .doc
If I give it the wrong extension, will it actually cause any issues?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Files are internally identified as well, so applications that can read either format will not have any trouble. Explorer will open the application that the extension points to, so double-clicking on the file name in explorer will call on Word to open it.

If the user does a Save As, Word will save it as RTF  by default and suggest an rtf extension.  You may consider this an issue.
0
 
LVL 1

Author Comment

by:jdhackett
Comment Utility
Hmm, so it does. Thanks for spotting that.
Is there a way around this?
Or a different command that does let me create an actual Word Doc?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
I think rtf was chosen as being the more open format. If you have Word, you could add code to open the file in Word and save it again in Document format. The snippet uses early binding, so needs a reference (Tools/References in VBA editor) to the Microsoft Word Object Library
    Dim wdAPP As Word.Application

    Dim wdDoc As Word.Document

    

    Set wdAPP = New Word.Application

    wdAPP.Visible = True 'optional

    Set wdDoc = wdAPP.Documents.Open("C:\MyFolder\MyFile.rtf")

    wdDoc.SaveAs "C:\MyFolder\MyFile.doc", wdFormatDocument

    wdDoc.Close wdDoNotSaveChanges

    wdAPP.Quit

    Kill "C:\MyFolder\MyFile.rtf"

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

762 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

9 Experts available now in Live!

Get 1:1 Help Now