I have a storage database that tracks tenants and payments and rent. I have a report for Payment History and titled the same. However, when the button is pushed, it says "printing to 'theprintersname'" then the database crashes.
The same code is used for a different database to print a report of the workdays incoming payments for all businesses. (my company has multiple entities within it).
That report prints just fine!
The report is bound to a query with the following sql (the parameters are retrieved from an unbound form [which has the print button on it])
Code:
SELECT Payment.LeaseID, Tenant.TenantName, [Year] & " - " & [Month] AS PaymentFor, Payment.DateDue, Payment.DatePaid, Payment.AmtDue, Payment.PaymentTypeID, Payment.PaymentCategoryID, Payment.ReferenceNumber, Payment.Amount, Payment.Notes, Payment.PaymentID, Payment.DateAdded, Payment.Balance, Month([DateDue]) AS MonthNum, Year([DateDue]) AS [Year], MonthName([MonthNum],True) AS [Month]
FROM Tenant INNER JOIN (Lease INNER JOIN Payment ON Lease.LeaseID = Payment.LeaseID) ON Tenant.TenantID = Lease.TenantID
WHERE (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)>=[Forms]![SelectLease]![DateFrom] And (Payment.DateDue)<[Forms]![SelectLease]![DateTo]+1) AND ((Lease.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit])) OR (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)>=[Forms]![SelectLease]![DateFrom] And (Payment.DateDue)<[Forms]![SelectLease]![DateTo]+1) AND (([Forms]![SelectLease]![cboLeaseUnit]) Is Null)) OR (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)<[Forms]![SelectLease]![DateTo]+1) AND ((Lease.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND (([Forms]![SelectLease]![DateFrom]) Is Null)) OR (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)<[Forms]![SelectLease]![DateTo]+1) AND (([Forms]![SelectLease]![cboLeaseUnit]) Is Null) AND (([Forms]![SelectLease]![DateFrom]) Is Null)) OR (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)>=[Forms]![SelectLease]![DateFrom]) AND ((Lease.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND (([Forms]![SelectLease]![DateTo]) Is Null)) OR (((Payment.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND ((Payment.DateDue)>=[Forms]![SelectLease]![DateFrom]) AND (([Forms]![SelectLease]![cboLeaseUnit]) Is Null) AND (([Forms]![SelectLease]![DateTo]) Is Null)) OR (((Lease.LeaseID)=[Forms]![SelectLease]![cboLeaseUnit]) AND (([Forms]![SelectLease]![DateFrom]) Is Null) AND (([Forms]![SelectLease]![DateTo]) Is Null)) OR ((([Forms]![SelectLease]![cboLeaseUnit]) Is Null) AND (([Forms]![SelectLease]![DateFrom]) Is Null) AND (([Forms]![SelectLease]![DateTo]) Is Null))
ORDER BY Payment.DateDue;
as you can see there is a TON of criteria.
this may put it into perspective a bit better

The form is a simple unbound form with text boxes for dateto and datefrom and combo boxes for select tenant and select lease

The code behind the report on open event is
Code:
Private Sub Report_Open(Cancel As Integer)
Const FORMNOTOPEN = 2450
Dim frm As Form
On Error Resume Next
Set frm = Forms!SelectLease
If Err = FORMNOTOPEN Then
DoCmd.OpenForm "SelectLease"
Cancel = True
Else
If Err <> 0 Then
' unknown error
MsgBox Err.Description, vbExclamation, "Error"
End If
End If
End Sub
and the code behind the print button is
Code:
Private Sub cmdPrint_Click()
Const REPORTCANCELLED = 2501
On Error Resume Next
DoCmd.OpenReport "Payment History", acViewNormal
Select Case Err.Number
Case 0
DoCmd.Close acForm, "SelectLease"
Case REPORTCANCELLED
MsgBox Err.Description, vbInformation, "Error: Report Cancelled!"
Case Else
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description, vbInformation, "Error:Unknown"
End Select
End Sub
I have no idea why it would be crashing the database. I can open the query and type in the parameters via the popup boxes and view it with no problem. I can also view the report by entering in the filter manually in design view and opening the selectlease form in design view then opening the history report normally. It shows the correct data.
I use the same print button in another database with no problems! I've tried in both access 2013 and 2016. The problem exists with both!
I'm stumped!