I am building a routine that formats a letter as an Access report then creates a word document from it.
There are a few fields where the user enters Name, Company and Address. There is a listbox that is populated with info for the letter. They click a button and the report opens (letter).
Everything is fine in the report. When word opens the access report is passed to word and a word doc is created. All the textboxes from the report are correct in the word doc, however the values from the listbox are not in the word doc (but appear in the access report). How can I get that info to the word doc.
I am not sure what I need to do.
Heres the code....
strFileName = Me.txtRecipient & Month(Date) & Day(Date)
Call ExportToRTF("rptLetter", "G:\Docs\" & strFileName, "Report")
Sub ExportToRTF(strName As String, strPath As String, Optional strItem As String = "Report")
Dim intType As Integer
Dim strRtFile As String
Dim wdApp As Word.application
intType = acReport
Set wdApp = CreateObject("Word.Application")
' select the object in the database window
DoCmd.SelectObject intType, strName, True
' output the document to word
DoCmd.RunCommand acCmdOutputToRTF
' find RTF name and path
strRtFile = wdApp.ActiveDocument.FullName
' Save the document as a word document in the required place
wdApp.ActiveDocument.SaveAs strPath, wdFormatDocument
'wdApp.Quit
Set wdApp = Nothing
'delete the RTF file since it's not needed
Kill strRtFile
End Sub
There are a few fields where the user enters Name, Company and Address. There is a listbox that is populated with info for the letter. They click a button and the report opens (letter).
Everything is fine in the report. When word opens the access report is passed to word and a word doc is created. All the textboxes from the report are correct in the word doc, however the values from the listbox are not in the word doc (but appear in the access report). How can I get that info to the word doc.
I am not sure what I need to do.
Heres the code....
strFileName = Me.txtRecipient & Month(Date) & Day(Date)
Call ExportToRTF("rptLetter", "G:\Docs\" & strFileName, "Report")
Sub ExportToRTF(strName As String, strPath As String, Optional strItem As String = "Report")
Dim intType As Integer
Dim strRtFile As String
Dim wdApp As Word.application
intType = acReport
Set wdApp = CreateObject("Word.Application")
' select the object in the database window
DoCmd.SelectObject intType, strName, True
' output the document to word
DoCmd.RunCommand acCmdOutputToRTF
' find RTF name and path
strRtFile = wdApp.ActiveDocument.FullName
' Save the document as a word document in the required place
wdApp.ActiveDocument.SaveAs strPath, wdFormatDocument
'wdApp.Quit
Set wdApp = Nothing
'delete the RTF file since it's not needed
Kill strRtFile
End Sub