I have a button on a report and when I click that button I want the option to export to pdf or excel. I have tried multiple coding options and ended up with the following:
Code:
Private Sub cmdExport_Click()
Dim tag As String
If MsgBox("Do you want to export to Excel?" , _
vbQuestion + vbYesNo) = vbYes Then
DoCmd.OutputTo acOutputReport, "rptCA", acFormatXLSX, "C:\"
Reports("rptCA").page.Orientation = acPRORLandscape
DoCmd.OpenReport "rptCA", acViewNormal
End If
If vbQuestion + vbYesNo = vbNo Then
DoCmd.OutputTo acOutputReport, "rptCA", acFormatPDF
Reports("rptCA").page.Orientation = acPRORLandscape
DoCmd.OpenReport "rptCA", acViewNormal
End If
End Sub
The problem is no matter if I click Yes or No, it always goes to PDF.