
Originally Posted by
Micron
If the forms are open and the controls contain values, there should be no parameter prompt, so I guess one or both of those conditions are not true. You cannot easily code to override a parameter prompt - unless you are quite able to code to test if the form(s) in question is/are open AND the specified controls are not null AND can then base the report on one of two query defs - one with and one without parameters.
IMHO, I think the simplest approach would be to provide an option in the user interface (report generating form?) where you're opening the reports from. This could be checkboxes or option buttons in a grouping frame for example. The setting determines if the reports are based on the sql with parameters or not. You can either construct one query for each option, or build the sql in code according to the setting and open the report based on the desired sql. Hope that's not too confusing of an explanation.
Thanks Micron, that gave me the idea of how to solve this issue,
Since the query automatically assigns "*" when the form is open, I decided to create a DoCmd.Openform before and another one to close it after the file is generated so it looks like below, (in this example, only the first file requires parameters) and it worked fine!
Code:
Private Sub btn_Send_Click()
Dim oApp As Object
Dim oEmail As Object
Dim fileName1 As String, todayDate As String, fileName2 As String
DoCmd.OpenForm "frm-Expired"
todayDate = Format(Date, "MMDDYYYY")
fileName1 = "\\mxchi-fs02\danmexshr\BD\Certificaciones\Reports" & "\Report-Expired_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "Reporte Vencídos", acFormatPDF, fileName1, False
DoCmd.Close acForm, "Frm-Expired", acSaveNo
fileName2 = "\\mxchi-fs02\danmexshr\BD\Certificaciones\Reports" & "\Report-ScheduledTop_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "Report-ScheduledTop", acFormatPDF, fileName2, False
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(0)
oEmail.To = DLookup("
[Lista]", "[tbl-sendlist]", "[ID]= 1")
oEmail.Subject = "Test"
oEmail.Body = "Testing"
oEmail.Attachments.Add fileName1
oEmail.Attachments.Add fileName2
oEmail.Send
MsgBox "Email Sent"
End Sub