N
Nick X
Hi all,
I have an Access db that is used by another piece of software (which I have
no access to that code) as a delivery system for reports. I am able to
manipulate the Access portion and have been able to open the reports based on
a selection in an Option Group . Now I am trying to use Allen Browne's "Open
the report filtered to the items selected in the list box.", but i can't
quite figure out how to twist it into this situation (I have gotten it to
work before). Remember, the reports are launched from a third party software
that I do not control. So i I need to get this to work in the OpenReport
procedure. thanks!
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmSelectFunc", , , , , acDialog
If Not IsLoaded("frmSelectFunc") Then
Cancel = True
End If
DoCmd.Maximize
End Sub
Private Sub cmdPrevFunc_Click()
'On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
'strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "Report by Priority Ranking"
'Loop through the ItemsSelected in the list box.
With Me.lstFuncClass
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(2, varItem) & """, "
End If
Next
End With
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
'DoCmd.Close acReport, strDoc
End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
Me.Visible = False
'Exit_Handler:
' Exit Sub
'Err_Handler:
' If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
' MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
' End If
' Resume Exit_Handler
End Sub
I have an Access db that is used by another piece of software (which I have
no access to that code) as a delivery system for reports. I am able to
manipulate the Access portion and have been able to open the reports based on
a selection in an Option Group . Now I am trying to use Allen Browne's "Open
the report filtered to the items selected in the list box.", but i can't
quite figure out how to twist it into this situation (I have gotten it to
work before). Remember, the reports are launched from a third party software
that I do not control. So i I need to get this to work in the OpenReport
procedure. thanks!
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmSelectFunc", , , , , acDialog
If Not IsLoaded("frmSelectFunc") Then
Cancel = True
End If
DoCmd.Maximize
End Sub
Private Sub cmdPrevFunc_Click()
'On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
'strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "Report by Priority Ranking"
'Loop through the ItemsSelected in the list box.
With Me.lstFuncClass
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(2, varItem) & """, "
End If
Next
End With
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
'DoCmd.Close acReport, strDoc
End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
Me.Visible = False
'Exit_Handler:
' Exit Sub
'Err_Handler:
' If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
' MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
' End If
' Resume Exit_Handler
End Sub