jeran042
Registered User.
- Local time
- Yesterday, 18:43
- Joined
- Jun 26, 2017
- Messages
- 127
I have a function that will output a report to a specified folder, and what I am trying to do is count the number of records before the report is exported, so if there are 0, I do not want to oputput anything.
Seems easy enough, and I thought I was accounting for this in my code. The problem is that the count of the recordsource is counting the total number of records in the query (which is returning the correct number of 18), and not the count of records in the report.
Here is what I have for code:
What am I missing?
I even changed:
to
With no luck
Seems easy enough, and I thought I was accounting for this in my code. The problem is that the count of the recordsource is counting the total number of records in the query (which is returning the correct number of 18), and not the count of records in the report.
Here is what I have for code:
Code:
Private Sub btnPDF_Click()
'PDF the Cases Report for the department Selected
'Error handling
On Error GoTo Error_Handler
Dim strFormName As String
Dim myPath As String
Dim iDepartment As Integer
Dim sReportName As String
Dim sDepartment As String
Dim sRecordSource As String
'Set references
myPath = "Y:\Budget process information\BUDGET DEPARTMENTS\3. CASES\"
iDepartment = Me.cboDEPARTMENT.Column(0)
sDepartment = Me.cboDEPARTMENT.Column(1)
strFormName = sDepartment & "_" & "Case Report" & Format(Date, "_mmddyy") & ".pdf"
sReportName = "RPT: CASES"
'Open the Cases Report, then count the number of cases
DoCmd.OpenReport sReportName, acViewReport, , "[COST_CENTER] = " & iDepartment
sRecordSource = Reports(sReportName).RecordSource
'Check if there any record to output
If DCount("*", sRecordSource) > 0 Then
DoCmd.OutputTo acOutputReport, sReportName, acFormatPDF, myPath + strFormName, True
DoCmd.Close acReport, sReportName, acSaveNo
MsgBox " Your Report Has Successfully Run " & _
vbCrLf & " You can find it at: " & myPath
Else
DoCmd.Close acReport, sReportName, acSaveNo
MsgBox "There are no Cases associated with: " & vbNewLine _
& sDepartment, vbInformation, "NO CASES"
End If
Error_Handler_Exit:
Exit Sub
Error_Handler:
Select Case Err.Number
Case 2501
Err.Clear
Resume Error_Handler_Exit
Case Else
MsgBox "Error No. " & Err.Number & vbCrLf & "Description: " & Err.Description, vbExclamation, "Database Error"
Err.Clear
Resume Error_Handler_Exit
End Select
End Sub
What am I missing?
I even changed:
Code:
If DCount("*", sRecordSource) > 0 Then
Code:
If DCount("*", me.RecordSource) > 0 Then