I don't see gbuLocation anywhere in that code.
Given you essentially copied the code I gave you, where's your call to
Crystal's routine:
Call SetReportFilter(stDocName, strWhere)
(and don't forget you need to copy Crystal's routine into your application)
Private Sub cmdSelect_Click()
Dim strError As String
Dim strWhere As String
Dim varItem As Variant
Dim stDocName As String
If IsNull(Me.txtStart)
strError = "Please enter a start date to run this report." & vbCrLf
End If
If IsNull(Me.txtEnd) Then
strError = strError & "Please enter an end date to run this report."
& vbCrLf
End If
If Me.lstArea.ItemsSelected.Count = 0 Then
strError = strError & "Please pick an item in lstArea." & vbCrLf
End If
If Me.lstProduct.ItemsSelected.Count = 0 Then
strError = strError & "Please pick an item in lstProduct." & vbCrLf
End If
If IsNull(Me.cboReviewer) = True Then
strError = strError & "Please pick an item in cboReviewer." & vbCrLf
End If
If Len(strError) > 0 Then
MsgBox strError
Else
strWhere = "[issueclosedate] between " & _
Format(Me.txtStart, "\#mm\/dd\/yyyy\#") & _
" And " & Format(Me.txtEnd, "\#mm\/dd\/yyyy\#") & _
" Field1 In ("
For Each varItem In Me.lstArea.ItemsSelected
strWhere = strWhere & Me.lstArea.ItemData(varItem) & ", "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND Field2 In ("
For Each varItem In Me.lstProduct.ItemsSelected
strWhere = strWhere & Chr$(34) & Me.lstArea.ItemData(varItem) & _
Chr$(34) & ", "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND " & _
"Field3 = " & Chr$(34) & Me.cboReviewer & Chr$(34)
stDocName = "rptQualityAuditList"
Call SetReportFilter(stDocName, strWhere)
DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , , True
End If
End Sub
You DO realize, I hope, that you need to replace Field1, Field2 and Field3
with the actual names of the fields you're trying to filter on?
If that doesn't work, what happens if you run:
DoCmd.OpenReport stDocName, acNormal, , strWhere
instead of the SendObject?
If still no joy, put
Debug.Print strWhere
instead of either the SendObject or OpenReport statement, then go to the
Immediate Window (Ctrl-G) and see what's printed there. Does it look
reasonable?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Dan @BCBS said:
Private Sub cmdSelect_Click()
Dim strError As String
Dim strWhere As String
Dim varItem As Variant
Dim stDocName As String
Dim stLinkCriteria As String
If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else
stLinkCriteria = "[issueclosedate] between #" & Me.txtStart & "# and
#" & Me.txtEnd & "#"
End If
If Me.lstArea.ItemsSelected.Count = 0 Then
strError = "Please pick an item in lstArea." & vbCrLf
End If
If Me.lstProduct.ItemsSelected.Count = 0 Then
strError = strError & "Please pick an item in lstProduct." & vbCrLf
End If
If IsNull(Me.cboReviewer) = True Then
strError = strError & "Please pick an item in cboReviewer." & vbCrLf
End If
If Len(strError) > 0 Then
MsgBox strError
Else
strWhere = "Field1 In ("
For Each varItem In Me.lstArea.ItemsSelected
strWhere = strWhere & Me.lstArea.ItemData(varItem) & ", "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND Field2 In ("
For Each varItem In Me.lstProduct.ItemsSelected
strWhere = strWhere & Chr$(34) & Me.lstArea.ItemData(varItem) & _
Chr$(34) & ", "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND " & _
"Field2 = " & Chr$(34) & Me.cboReviewer & Chr$(34)
stDocName = "rptQualityAuditList"
DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , , True
'DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
End If
End Sub
Douglas J Steele said:
Show the actual code you're using.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Dan @BCBS said:
Because of this error I added the following.
Although I do not get any errors - a pop up flashes "now outputting reprot
to email.... So, replaced:
DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , , True
"with"
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
Any Suggestions, I know I'm close with your help..
Dim stLinkCriteria As String
If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else
stLinkCriteria = "[issueclosedate] between #" & Me.txtStart &
"#
and
#" & Me.txtEnd & "#"
End If
:
Syntax error in date in query expression '[gbuLocation] and [issueclosedate]
between ## and ##'.
The [issueclosedate] = issueclosedate between #" & Me.txtStart & "#
and
#" &
Me.txtEnd & "#"
The [gbuLocation] = stLinkCriteria = "[gbulocation] " & stAreaList
& "
and
[insurancetype] " & stProductList
:
The text that accompanies the error should give some clue. What
does
it say?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Thanks for your time and patience.
No, to your first paragraph.
Yes, your assumptions are correct.
Everything except the Call seems to work correctly..
I assume this is where you tell me to call my report
(rptQuualityAuditList)..
I've tried a few combinations, most recent:
Dim stDocName As String
If.........
stDocName = "rptQualityAuditList"
DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , ,
,
True
Which gives me a runtime error '3075'
:
You missed my point. Your code isn't doing anything! You're
not
trying
to
tell me that you get different results depending on what
values
are in
txtStar or txtEnd, or what's been selected in lstArea are you?
Without knowing the names of your table fields and form
controls,
it's
difficult for me to give you a precise answer.
I'll make the following assumptions:
- you want to compare what's in numeric field Field1 to what's been
selected
in list box Listbox1
- you want to compare what's in text field Field2 to what's been
selected in
list box Listbox2
- you want to compare what's in text field Field3 to what's been
selected in
combo box Combobox1
- you want to launch report MyReport, but only if at least 1 record has
been
selected in Listbox1, at least one record has been selected in Listbox2
and
a record has been selected in Combobox1
That out of the way, you need code like:
Dim strError As String
Dim strWhere As String
Dim varItem As Variant
If Me.Listbox1.ItemsSelected.Count = 0 Then
strError = "Please pick an item in Listbox1." & vbCrLf
End If
If Me.Listbox2.ItemsSelected.Count = 0 Then
strError = strError & "Please pick an item in Listbox2."
&
vbCrLf
End If
If IsNull(Me.Combobox1) = True Then
strError = strError & "Please pick an item in
Combobox2." &
vbCrLf
End If
If Len(strError) > 0 Then
Msgbox strError
Else
strWhere = "Field1 In ("
For Each varItem In Me.Listbox1.ItemsSelected
strWhere = strWhere & Me.Listbox1.ItemData(varItem) &
",
"
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND
Field2
In ("
For Each varItem In Me.Listbox2.ItemsSelected
strWhere = strWhere & Chr$(34) & Me.Listbox1.ItemData(varItem)
& _
Chr$(34) & ", "
Next varItem
strWhere = Left(strWhere, Len(strWhere) - 2) & ") AND " & _
"Field2 = " & Chr$(34) & Me.Combobox1 & Chr$(34)
Call SetReportFilter("MyReport", strWhere)
DoCmd.SendObject acReport, "MyReport", acFormatRTF, , ,
, ,
, True