This Report is in Access and is name rpt1, It isn't opening like it should. Please Help... Thank you.
Expand|Select|Wrap|Line Numbers
- Private Sub cmdApplyFilter_Click()
- Dim varItem As Variant
- Dim strAction_Types_Choices As String
- Dim strReason_Choices As String
- Dim strPosition As String
- Dim strFilter As String
- Dim StrSortOder As String
- If SysCmd(acSysCmdGetObjectState, acReport, "rpt1") <> acObjStateOpen Then
- MsgBox "You must open the report first."
- Exit Sub
- End If
- For Each varItem In Me.LstAction_Type.ItemsSelected
- strAction_Types_Choices = strAction_Types_Choices & ",'" & Me.LstAction_Type.ItemData(varItem) & "'"
- Next varItem
- If Len(strAction_Types_Choices) = 0 Then
- strAction_Types_Choices = "Like '*'"
- Else
- strAction_Types_Choices = Right(strAction_Types_Choices, Len(strAction_Types_Choices) - 1)
- strAction_Types_Choices = "IN(" & strAction_Types_Choices & ")"
- End If
- For Each varItem In Me.LstReason.ItemsSelected
- strReason_Choices = strReason_Choices & ",'" & Me.LstReason.ItemData(varItem) & "'"
- Next varItem
- If Len(strReason_Choices) = 0 Then
- strReason_Choices = "Like '*'"
- Else
- strReason_Choices = Right(strReason_Choices, Len(strReason_Choices) - 1)
- strReason_Choices = "IN(" & strReason_Choices & ")"
- End If
- For Each varItem In Me.LstPosition.ItemsSelected
- strPosition = strPosition & ",'" & Me.LstPosition.ItemData(varItem) & "'"
- Next varItem
- If Len(strPosition) = 0 Then
- strPosition = "Like '*'"
- Else
- strPosition = Right(strPosition, Len(strPosition) - 1)
- strPosition = "IN(" & strPosition & ")"
- End If
- strFilter = "[Action_Types_Choices] " & strAction_Type_Choices & " AND [Reason_Choices] " & strReason_Choices & " AND [Position]" & strPosition
- If Me.cboSortOrder1.Value <> "Not Sorted" Then
- strSortOrder = "[" & Me.cboSortOrder1.Value & "]"
- If Me.cmdSortDirection1.Caption = "Descending" Then
- strSortOrder = strSortOrder & " DESC"
- End If
- If Me.cboSortOrder2.Value <> "Not Sorted" Then
- strSortOrder = strSortOrder & ",[" & Me.cboSortOrder2.Value & "]"
- If Me.cmdSortDirection2.Caption = "Descending" Then
- strSortOrder = strSortOrder & " DESC"
- End If
- If Me.cboSortOrder3.Value <> "Not Sorted" Then
- strSortOrder = strSortOrder & ",[" & Me.cboSortOrder3.Value & "]"
- If Me.cmdSortDirection3.Caption = "Descending" Then
- strSortOrder = strSortOrder & " DESC"
- End If
- End If
- End If
- End If
- With Reports![rpt1]
- .Filter = strFilter
- .FilterOn = True
- .OrderBy = strSortOrder
- .OrderByOn = True
- End With
- End Sub
- _______________________________________________________
- Private Sub cmdApplyFilter_Click()
- On Error GoTo Err_cmdApplyFilter_Click
- Dim stDocName As String
- stDocName = "rpt1"
- DoCmd.OpenReport stDocName, acPreview
- Exit_cmdApplyFilter_Click:
- Exit Sub
- Err_cmdApplyFilter_Click:
- MsgBox Err.Description
- Resume Exit_cmdApplyFilter_Click
- End Sub
- Dim Response As VbMsgBoxResult
- If SysCmd(acSysCmdGetObjectState, acReport, "rpt1") <> acObjStateOpen Then
- Response = MsgBox("The report is not open." _
- & vbCrLf & "Do you want to open it now?" _
- , vbQuestion + vbYesNoCancel)
- SelectCase Response
- Case vbYes
- DoCmd.OpenReport "rpt1", acViewPreview
- Case vbNo
- Exit Sub
- Case vbCancel
- DoCmd.Close acForm, Me.Name
- Exit Sub
- End Select
- End If