Capturing the text from DoCmd.Output in MS Access

Hi all,
I hope someone can help me with this one.  We are trying to get rid of extra line feeds that are appearing in the text output of our microsoft access reports.  The command being used is:
DoCmd.OutputTo acOutputReport, reportName, acFormatTXT, printFileName, False, "", varEncoding

We've tried many methods to rid ourselves of the extra line spaces such as setting the Can Grow, Can Shrink options to TRUE for Report Sections and for text fields.  And we've tried widening the fields to make the vertical space smaller but so far, no luck.

We've also considered saving the output to the hard drive as a text file and then just running a filter to eliminate the extra line feeds but that would add precious seconds to each transaction of thousands and so therefore this is unacceptable.

So far it looks like we have to find a solution within the actual report or within the application.

Has anyone else had some success with this kind of issue?
Thank you

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
It's probably got to do with the way Access formats these reports for the acFormatTXT format ... not sure what can be done, other than to play around with this until you hit upon the right combination.

You could output directly to a Text file, if that would be more suitable. Access/VBA provides quite a few methods to write directly to Text files, if that would suit you better.

Make control height and detail section height a multiple of 0.125".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:

I would go with LSMConsulting's sugestion and just outputting to a text file.

<We've also considered saving the output to the hard drive as a text file and then just running a filter to eliminate the extra line feeds but that would add precious seconds to each transaction of thousands and so therefore this is unacceptable.>
If you export the underlying query or table, as delimited text, there will be no "Extra line feeds":
DoCmd.TransferText acExportDelim, , "UnderlyingQueryOrTableName", "FullPathFileNameAndExtensionOfYourTextFile"

The OutputTo command *Tries* to format the rtf to look like the Report, but it is far from perfect.
Word an Access dispay objects in totally different ways.

However the Help file on the outputTo Action does provide some pretty useful tips on formatting, among the most usefull are:
-You can size the controls by pointing to Size on the Format menu, and then clicking To Fit.
-You should avoid overlapping controls or placing controls too close together.
-You can align the controls on the report by pointing to Align on the Format menu, and then clicking the appropriate command. Controls that aren't aligned in the same row may be placed in separate rows in the output file, causing additional spacing.

Do the users need to edit this file? (hence the need for outputto rtf)

If not, please consider the the other output options:
SnapShot, HTML, and of course, PDF.

HTH as well


RE: Direct to text

If your reports are simple enough writing directly to the .txt file is probably the way to go. I use FileSystemObject (add reference to Microsoft Scripting Runtime) instead of the VBA functions.

Attached is a routine that processes some text, updating within select fields, and writes CSV lines to a text file.
        Dim fso As New FileSystemObject
        Dim ts As TextStream
        v = Split(sData, vbCrLf)
        Set ts = fso.OpenTextFile(sDir & "stop_times.txt", ForWriting, True)
        ts.WriteLine v(0) ' header
        For i = 1 To UBound(v)
            If Len(v(i)) Then
                v2 = Split(v(i), ",") ' shouldn't be any commas in stop_times beside field delimiters
                v2(1) = Replace(v2(1), "_", ":")
                v2(2) = Replace(v2(2), "_", ":")
                ts.WriteLine Join(v2, ",")
            End If
        Next i

Open in new window

tcalbazAuthor Commented:
Guys, thanks for your help.  rheitzman and boag2000 both provided solid approaches to resolving the problem.  rheitzman your last response about writing directly to a text file though it wasn't utilized because of server timing considerations offered a possible new way of resolving things in the future.  


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.