Putting a single record into Word

Nwalach

Registered User.
Local time
Today, 15:02
Joined
Jun 2, 2003
Messages
12
Hey, I've got a (most likely) simple question for anyone with the time to answer it. I have a report set up and I want to be able to export a single record to a word document. I know how to export a report with OutputTo, and I know how to open a single record with OpenReport, but I can't seem to figure out how to accomplish both tasks. Is there a way to do OpenReport, give it a temporary name and then output that report?

Help would be greatly appreciated. I am new to access and I've been doing okay, but this point has me fairly well stumped. So far reading previous posts on this board has been a Godsend for my project, so I was hoping someone might have the answer I seek.

Thanks,
Nick
 
Nick,

You can create a command button on your form to print a specific record (one that is displayed), by writing a macro to "OpenReport" with a Where statement isolating your report data to a unique field from your form (i.e. ID): "[ID]=[Forms]![FormName]![ID]. Then use "OutputTo" to send your report to Word, etc. You can also set this to either prompt for a file name or give the file a name from your record. OR you can just click the Publish To Word button in print preview mode...

Hope this is what you are looking for.
 
Yeah, I'd tried that but hit some snags. Mostly, I can't figure out how to call to the Report I've opened in the OutputTo function. Here is my code:

Private Sub Command32_Click()
On Error GoTo Err_Command32_Click

Dim DocName As String
Dim WordObj As Object
Dim RptWhere As String
Dim rtp As Report

RptWhere = "[ID] = " & Me.ID
DocName = "Article: Single Attributes"
DoCmd.OpenReport DocName, , , RptWhere


DoCmd.OutputTo acOutputReport, DocName, acFormatRTF, "Template.doc", True





Exit_Command32_Click:
Exit Sub

Err_Command32_Click:
MsgBox Err.Description
Resume Exit_Command32_Click

End Sub

I left a space where I'm sure something is missing. Also, for some crazy reason it prints whenever I run this. Any ideas? I really appreciate the help.

Thanks,
Nick
 
Got it!

I didn't realize the default value that opened the report would automatically print it. I set it to acViewPreview and it works flawlessly.

Thank you so much.

Nick
 
Try this to prevent the auto print:

DoCmd.OpenReport DocName, acPreview, , RptWhere

Word should be opening upon output because of your "True" at the end of your OutputTo line. May need to try "RichTextFormat(*.rtf)" in place of acFormatRTF. Or you may be catching an error with your filename "Template.doc" because you are actually saving in RTF format - this can cause a hang. Changing the filename to "Template.rtf" will also open Word if the .rtf extension is so associated.

If this doesn't fly, you could also use a macro vice VB - 2 lines, very simple:

OpenReport
Report Name: Article: Single Attributes
View: Print Preview
Filter Name:
Where Condition: [ID]=[Forms]![~formname~]![ID]

OutputTo
Object Type: Report
Object Name: Article: Single Attributes
Output Format: Rich Text Format
Output File: Template.rtf
Auto Start: Yes
Template File:

Save the macro and set your Command32 button's OnClick property to the name of your macro. This may work better for you (or not).
 

Users who are viewing this thread

Back
Top Bottom