Code:
Private Sub btnPrintSummary_Click()
Dim stDocName As String
Dim stWhere As String
Dim blnTrim As Boolean
If Not IsNull(Me.cboMonth) Then
stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
blnTrim = True
End If
If Not IsNull(Me.cboYear) Then
stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
blnTrim = True
End If
If blnTrim Then
stWhere = Left(stWhere, Len(stWhere) - 5)
End If
stDocName = "RptSalarySummary"
DoCmd.OpenReport stDocName, acPreview, , stWhere
Exit Sub
'DoCmd.OpenQuery "qrySalarySummary", acViewNormal
End Sub
Did you set a breakpoint, 'message box' or 'Debug.Print' to see what the value of stWhere was just before the report open statement?
It looks to me that you are cutting off the year because "blnTrim" is TRUE in the check to see if cboYear is NULL.
Try this:
Code:
Private Sub btnPrintSummary_Click()
Dim stDocName As String
Dim stWhere As String
Dim blnTrim As Boolean
If Not IsNull(Me.cboMonth) Then
stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
blnTrim = True
End If
If Not IsNull(Me.cboYear) Then
stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
blnTrim = FALSE
End If
If blnTrim Then
stWhere = Left(stWhere, Len(stWhere) - 5)
End If
' remove or comment out when done troubleshooting
DEBUG.PRINT stWhere
stDocName = "RptSalarySummary"
DoCmd.OpenReport stDocName, acPreview, , stWhere
End Sub