Criteria for reports code problem

pablavo

Registered User.
Local time
Today, 02:33
Joined
Jun 28, 2007
Messages
189
Hi folks.

I wonder if someone can help me with some code.

I have an input form with my criteria text boxes. I set my criteria and I use the command button to preview my report.

I'm actually using two sets of code courtesy of Bob larson and Martin Green.

When I use one part of the code (blue), the report will open when I click the command. when I use the other part (Green), as well, and try to open the report, a dialog pops up stating that it cannot find the report. this part of the code seems only to work when the report is open. It's also making the first part of the code open the same dialog message. So unless the report is alreay open, the way I have the code is useless.

I'm trying to change the code so that I can use the criteria without the report being open and when I've set my criteria, then, I can preview the report.

Here's the code: (Error handling omitted and shortened for space)

Dim varItem As Variant
Dim strCountryProject As String
Dim strFilter As String
Dim strRptName As String
Dim stWhere As String
Dim blnTrim As Boolean

If Not IsNull(Me.cboCountry) Then
stWhere = stWhere & "[CountryID]=" & Me.cboCountry & " And "
blnTrim = True
End If

If blnTrim Then
stWhere = Left(stWhere, Len(stWhere) - 5)
End If



for Each varItem In Me.lstCountries.ItemsSelected
strCountryProject = strCountryProject & ",'" & Me.lstCountries.ItemData(varItem) _
& "'"
Next varItem
If Len(strCountryProject) = 0 Then
strCountryProject = "Like '*'"
Else
strCountryProject = Right(strCountryProject, Len(strCountryProject) - 1)
strCountryProject = "IN(" & strCountryProject & ")"
End If

strFilter = "[Country] " & strCountryProject

With Reports![rptImpact]
.Filter = strFilter
.FilterOn = True
End With



strRptName = "rptImpact"
DoCmd.OpenReport strRptName, acPreview, , stWhere

End Sub


I don't how this would be done so if someone has any ideas I'd be grateful

thanks
 

Users who are viewing this thread

Back
Top Bottom