Thanks. Here is the code in it's entirety.
Note there are 3 places where the WHERECLAUSE is failing.
This code was COPY/PASTED from another program of mine that works fine and
appropraite changes were made.
I have gotten around this by implementing code in the FORMAT event on the
detail section of the report, but I don't like doing it that way.
Private Sub btnPreview_Click()
Dim stDocName As String
Dim iMonth As Integer
Dim iYear As Integer
Dim iWork As Integer
Dim strg1 As String
On Error GoTo Err_btnPreview_Click
WhereClause = ""
Select Case Frame0.Value
Case 1
stDocName = "Labels Current Members"
Case 2
stDocName = "Renewal Labels"
iMonth = Month(txtDate.Value)
iYear = Year(txtDate.Value)
iWork = iMonth + (12 * iYear)
WhereClause = "ABS(" & Str(iWork) & " - GrossMonths) <= 1"
Case 3
stDocName = "Labels Current Members"
WhereClause = "ShortName = '" & cmbCategory.Value & "'"
Case 4
If IsNothing(cmbGroup.Value) Then
MsgBox "Please enter a GROUP name"
Exit Sub
End If
stDocName = "GroupDonationsSummary"
WhereClause = "StartDate <= #" & txtDate.Value
WhereClause = WhereClause & "# AND ((EndDate IS NULL) OR (EndDate >=
#" & txtDate.Value & "#))"
End Select
'MsgBox WhereClause
DoCmd.OpenReport stDocName, acPreview, , WhereClause
Exit_btnPreview_Click:
Exit Sub
Err_btnPreview_Click:
MsgBox Err.Description
Resume Exit_btnPreview_Click
End Sub ' btnPreview_Click
Brendan Reynolds said:
Hi Bill,
This obviously isn't the real code, as you've forgotten to include the
call to the OpenReport method. If you'll copy and paste the real code,
someone may be able to see what the problem is. You may need to include
the line that assigns a value to the WhereClause variable as well as the
call to the OpenReport method.