Export report to Word via VBA (1 Viewer)

gojets1721

Registered User.
Local time
Today, 04:07
Joined
Jun 11, 2019
Messages
429
So I've got the below code that works flawlessly to pull an entry from a form into a report that exports to a PDF. I'm trying to use the exact same code but to export to Microsoft Word instead (if possible). I've tried to use a few online guides but they don't mesh perfectly with my code and I'm admittedly still learning VBA. Any thoughts on what needs to be changed to export to Word rather than PDF?

Code:
Private Sub cmd_exportformPDF_Click()
    Dim reportName As String
    Dim criteria As String
    Dim strfolder As String
    Dim strfilename As String
    
    reportName = "CompletedForm"
    criteria = "[ComplaintNumber]= " & [Forms]![frm2021Details]![ComplaintNumber]
    strfolder = "F:\Documents"
    strfilename = Me.CustomerLastName & ", " & Me.CustomerFirstName & " " & Format(Me.DateOpened, "m.d.yyyy") & ".pdf"
    
    DoCmd.OpenReport reportName, acViewPreview, criteria, acHidden
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, strfolder & strfilename
    DoCmd.Close acReport, reportName, acSaveNo
 End Sub
 

Ranman256

Well-known member
Local time
Today, 07:07
Joined
Apr 9, 2015
Messages
4,337
You've already exported to PDF. Why is Word needed?
Tho you can export as RTF, acFormatRTF, which word uses.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:07
Joined
Feb 19, 2002
Messages
43,266
The export to word will eliminate any graphics in the report. What is the problem you are having?
 

gojets1721

Registered User.
Local time
Today, 04:07
Joined
Jun 11, 2019
Messages
429
You've already exported to PDF. Why is Word needed?
Tho you can export as RTF, acFormatRTF, which word uses.
I'm not replacing the PDF export with a Word one. All the complaints are stored as PDFs outside of the database (don't ask me why). That's what the pdf export is for.

Additionally, sometimes a manager at a location needs to add their follow-up on the complaint before its closed. We send it to them via Word and they send back. I've tried to get everyone to use the database but its not likely anytime soon. All the managers before Word documents unfortunately

Being able to export them as both a PDF and a Word would literally save hours of wasted time
 

gojets1721

Registered User.
Local time
Today, 04:07
Joined
Jun 11, 2019
Messages
429
I tried and it does export to Word, but when I try to open the file, I get a "unreadable content error. Do you wish to recover?". I don't have any images in the report so I'm not sure of the issue :/
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:07
Joined
May 7, 2009
Messages
19,242
you can also create a "Complaint" template in Word (with bookmarks).
and fill those bookmarks from table/query using VBA.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:07
Joined
Feb 19, 2002
Messages
43,266
If you post the database, one of us will test it to see if we get the same error.
 

bastanu

AWF VIP
Local time
Today, 04:07
Joined
Apr 13, 2010
Messages
1,402
As mentioned in your other post (https://www.accessforums.net/showthread.php?t=83741) have you tried to actually use the proper extension for the file name?
strfilename = Me.CustomerLastName & ", " & Me.CustomerFirstName & " " & Format(Me.DateOpened, "m.d.yyyy") & ".rtf" 'must use the extension that matches the OutputTo format argument not ".pdf"
Cheers,
 

Users who are viewing this thread

Top Bottom