Need to change DoCmd.OutputTo using Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ljungers
    New Member
    • Dec 2006
    • 114

    Need to change DoCmd.OutputTo using Word

    I need to make some changes to a Query/select/print report using word application. What I need to do is change the way Word is called yet keep the process the same. Word is used so changes can be made before actual printing. Need some way of calling Word as a mail merge with the information from an Access table that the current report uses.

    I have seen mail merge templates that use something like <<field name>> in them that uses a table. Reason for the change is the need for some graphics in the report and rtf will not carry the graphics across to word.

    Here is the current code that is used when a person selected the desired information from a list box and a command button is clicked and the following is performed.

    Code:
        Dim valSelect As Variant
        Dim strWhere As String
        Dim strSQLSelect As String
        Dim AnyItemsSelected As Boolean
        AnyItemsSelected = False
        Dim qd As DAO.querydef
        
        strWhere = "[rec_no] In ("
        For Each valSelect In Me.SelectPrintItems.ItemsSelected
            strWhere = strWhere & Me.SelectPrintItems.ItemData(valSelect) & ", "
            AnyItemsSelected = True
        Next valSelect
        strWhere = Left(strWhere, Len(strWhere) - 2) 'removes last comma and space
        strWhere = strWhere & ")"
        
        If AnyItemsSelected = False Then
            MsgBox ("You must make a selection(s) from the list before sending to Word !")
            GoTo Exit_Send2WordButton_Click
        Else
            strSQLSelect = "SELECT rec_no, med_rec_no, first_name, last_name, trans_memo " & _
            "FROM Translated_memo WHERE " & strWhere
            Set qd = CurrentDb.QueryDefs("send2WordQuery")
            qd.SQL = strSQLSelect 'fill SQL
            MsgBox ("Only one MS Word document may be open at a time. After you Edit and Print " & _
            "you may want to Save the document before exiting Word!")
            DoCmd.OutputTo acOutputReport, "Trans_memo_141_Word", acFormatRTF, "Selected_141_report.rtf", True
        End If
    Can the DoCmd.OutputTo be changed to use a mail merge document? I can create a word template that looks like the Access "Trans_memo_141 _Word" report if that is needed.

    Thanks in advance
    Last edited by NeoPa; Jan 9 '07, 08:41 PM. Reason: Tags
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by ljungers
    I need to make some changes to a Query/select/print report using word application. What I need to do is change the way Word is called yet keep the process the same. Word is used so changes can be made before actual printing. Need some way of calling Word as a mail merge with the information from an Access table that the current report uses.

    I have seen mail merge templates that use something like <<field name>> in them that uses a table. Reason for the change is the need for some graphics in the report and rtf will not carry the graphics across to word.

    Here is the current code that is used when a person selected the desired information from a list box and a command button is clicked and the following is performed.

    Code:
        Dim valSelect As Variant
        Dim strWhere As String
        Dim strSQLSelect As String
        Dim AnyItemsSelected As Boolean
        AnyItemsSelected = False
        Dim qd As DAO.querydef
        
        strWhere = "[rec_no] In ("
        For Each valSelect In Me.SelectPrintItems.ItemsSelected
            strWhere = strWhere & Me.SelectPrintItems.ItemData(valSelect) & ", "
            AnyItemsSelected = True
        Next valSelect
        strWhere = Left(strWhere, Len(strWhere) - 2) 'removes last comma and space
        strWhere = strWhere & ")"
        
        If AnyItemsSelected = False Then
            MsgBox ("You must make a selection(s) from the list before sending to Word !")
            GoTo Exit_Send2WordButton_Click
        Else
            strSQLSelect = "SELECT rec_no, med_rec_no, first_name, last_name, trans_memo " & _
            "FROM Translated_memo WHERE " & strWhere
            Set qd = CurrentDb.QueryDefs("send2WordQuery")
            qd.SQL = strSQLSelect 'fill SQL
            MsgBox ("Only one MS Word document may be open at a time. After you Edit and Print " & _
            "you may want to Save the document before exiting Word!")
            DoCmd.OutputTo acOutputReport, "Trans_memo_141_Word", acFormatRTF, "Selected_141_report.rtf", True
        End If
    Can the DoCmd.OutputTo be changed to use a mail merge document? I can create a word template that looks like the Access "Trans_memo_141 _Word" report if that is needed.

    Thanks in advance
    Create a mail merge document in word with 'send2WordQuery ' as the data source. Then instead of using the output to you could just open the word template you had designed.

    Mary

    Comment

    • ljungers
      New Member
      • Dec 2006
      • 114

      #3
      Thanks Mary for the info. Wondering if there is a way to start Word from within the VBA code instead of having to manually start Word.

      The only reason I'm chaing the working code is because they desire some graphics to print and that is not happening when I send the Access Report to Word in a rtf file.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Code:
        Private Sub CommandXX_Click()
        Dim wordDoc As String
        Dim accApp As Object
        
           wordDoc = "full path to document"
        
           If Dir(wordDoc) = "" Then
        	  MsgBox "Document not found."
           Else
        	  Set accApp = CreateObject(Class:="Word.Application")
        	  accApp.Visible = True
        	  accApp.Documents.Open filename:=wordDoc
           End If
        
           Set accApp = Nothing
        
        End Sub
        This is the code to open a word document. I've put the code in the button click event.

        Mary

        Comment

        Working...