Word
Code: Select all
Dim stDocName As String
Dim stFileName As String
stDocName = "Queryform2"
stFileName = "C:\" & stDocName & ".rtf"
DoCmd.OutputTo acReport, stDocName, acFormatRTF, stFileName, True
Excel
Code: Select all
Dim stDocName As String
Dim stFileName As String
stDocName = "Queryform2"
stFileName = "C:\" & stDocName & ".xls"
DoCmd.OutputTo acOutputReport, "QueryForm2", acFormatXLS, stFileName, True, "", , acExportQualityPrint
Code: Select all
Dim stDocName As String
Dim stFileName As String
stDocName = "Queryform2"
stFileName = "C:\" & stDocName & ".pdf"
DoCmd.OpenReport stDocName, acPreview, , Filter, acHidden
DoCmd.OutputTo acReport, stDocName, acFormatPDF, stFileName, True
DoCmd.Close acReport, stDocName
Another Excel report event also works as well as the PDF report. Any clues
Excel
Code: Select all
Dim rs As DAO.Recordset
Dim oXLApp As Excel.Application
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
If Me.LPP.RowSource = "" Then Exit Sub
Set oXLApp = New Excel.Application
Set oXLBook = oXLApp.Workbooks.Add
Set oXLSheet = oXLBook.ActiveSheet
Set rs = CurrentDb.OpenRecordset(Me.LPP.RowSource)
oXLSheet.Range("B2").CopyFromRecordset rs
oXLApp.Visible = True
oXLApp.UserControl = True
Set oXLBook = Nothing
Set oXLApp = Nothing
Set oXLSheet = Nothing
Many thanks