A
Alex
I created a dialog box(form) where users specify criteria for filtering a
report by picking choices from a multi-select list box and an option group.
The form has a button with code that constructs an SQL Where clause using the
users multi-select list box choices and option group choice. This works
great, but I have to create a chart using the same parameters. How do I
write in the Chart Row Source the code that is in the button on the dialog
box form? The code in the dialog box button is below: I'm used to using
queries for a chart Row Source. Thanks for your help.
Private Sub cmdApplyFilter_Click()
Dim VarItem As Variant
Dim strStore As String
Dim strLocation As String
Dim datBeginDate As Date
Dim datEndDate As Date
Dim strFilter As String
' Check that a location is selected
If Len(Me.cmdLocation.Value & "") = 0 Then
MsgBox "You must pick a location"
Exit Sub
End If
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "LocationsReportbyStorage")
<> acObjStateOpen Then
DoCmd.OpenReport "LocationsReportbyStorage", acViewPreview
'MsgBox "You must open the report first."
'Exit Sub
End If
'Build criteria for Date parameter range
' Build criteria string from StoreRoom listbox
For Each VarItem In Me.cmdStoreRoom.ItemsSelected
strStore = strStore & ",'" & Me.cmdStoreRoom.ItemData(VarItem) _
& "'"
Next VarItem
If Len(strStore) = 0 Then
strStore = "Like '*'"
Else
strStore = Right(strStore, Len(strStore) - 1)
strStore = "IN(" & strStore & ")"
End If
' Build criteria string from Location option group
Select Case Me.cmdLocation.Value
Case 1
strLocation = "='1'"
Case 2
strLocation = "='2'"
End Select
' Build filter string
strFilter = "[StorageRoom] " & strStore & " AND [Location] " & strLocation
' Apply the filter and switch it on
With Reports![LocationsReportbyStorage]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdApplyFilter_Click()
Dim VarItem As Variant
Dim strStore As String
Dim strLocation As String
Dim datBeginDate As Date
Dim datEndDate As Date
Dim strFilter As String
' Check that a location is selected
If Len(Me.cmdLocation.Value & "") = 0 Then
MsgBox "You must pick a location"
Exit Sub
End If
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "LocationsReportbyStorage")
<> acObjStateOpen Then
DoCmd.OpenReport "LocationsReportbyStorage", acViewPreview
'MsgBox "You must open the report first."
'Exit Sub
End If
'Build criteria for Date parameter range
' Build criteria string from StoreRoom listbox
For Each VarItem In Me.cmdStoreRoom.ItemsSelected
strStore = strStore & ",'" & Me.cmdStoreRoom.ItemData(VarItem) _
& "'"
Next VarItem
If Len(strStore) = 0 Then
strStore = "Like '*'"
Else
strStore = Right(strStore, Len(strStore) - 1)
strStore = "IN(" & strStore & ")"
End If
' Build criteria string from Location option group
Select Case Me.cmdLocation.Value
Case 1
strLocation = "='1'"
Case 2
strLocation = "='2'"
End Select
' Build filter string
strFilter = "[StorageRoom] " & strStore & " AND [Location] " & strLocation
' Apply the filter and switch it on
With Reports![LocationsReportbyStorage]
.Filter = strFilter
.FilterOn = True
End With
End Sub
report by picking choices from a multi-select list box and an option group.
The form has a button with code that constructs an SQL Where clause using the
users multi-select list box choices and option group choice. This works
great, but I have to create a chart using the same parameters. How do I
write in the Chart Row Source the code that is in the button on the dialog
box form? The code in the dialog box button is below: I'm used to using
queries for a chart Row Source. Thanks for your help.
Private Sub cmdApplyFilter_Click()
Dim VarItem As Variant
Dim strStore As String
Dim strLocation As String
Dim datBeginDate As Date
Dim datEndDate As Date
Dim strFilter As String
' Check that a location is selected
If Len(Me.cmdLocation.Value & "") = 0 Then
MsgBox "You must pick a location"
Exit Sub
End If
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "LocationsReportbyStorage")
<> acObjStateOpen Then
DoCmd.OpenReport "LocationsReportbyStorage", acViewPreview
'MsgBox "You must open the report first."
'Exit Sub
End If
'Build criteria for Date parameter range
' Build criteria string from StoreRoom listbox
For Each VarItem In Me.cmdStoreRoom.ItemsSelected
strStore = strStore & ",'" & Me.cmdStoreRoom.ItemData(VarItem) _
& "'"
Next VarItem
If Len(strStore) = 0 Then
strStore = "Like '*'"
Else
strStore = Right(strStore, Len(strStore) - 1)
strStore = "IN(" & strStore & ")"
End If
' Build criteria string from Location option group
Select Case Me.cmdLocation.Value
Case 1
strLocation = "='1'"
Case 2
strLocation = "='2'"
End Select
' Build filter string
strFilter = "[StorageRoom] " & strStore & " AND [Location] " & strLocation
' Apply the filter and switch it on
With Reports![LocationsReportbyStorage]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdApplyFilter_Click()
Dim VarItem As Variant
Dim strStore As String
Dim strLocation As String
Dim datBeginDate As Date
Dim datEndDate As Date
Dim strFilter As String
' Check that a location is selected
If Len(Me.cmdLocation.Value & "") = 0 Then
MsgBox "You must pick a location"
Exit Sub
End If
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "LocationsReportbyStorage")
<> acObjStateOpen Then
DoCmd.OpenReport "LocationsReportbyStorage", acViewPreview
'MsgBox "You must open the report first."
'Exit Sub
End If
'Build criteria for Date parameter range
' Build criteria string from StoreRoom listbox
For Each VarItem In Me.cmdStoreRoom.ItemsSelected
strStore = strStore & ",'" & Me.cmdStoreRoom.ItemData(VarItem) _
& "'"
Next VarItem
If Len(strStore) = 0 Then
strStore = "Like '*'"
Else
strStore = Right(strStore, Len(strStore) - 1)
strStore = "IN(" & strStore & ")"
End If
' Build criteria string from Location option group
Select Case Me.cmdLocation.Value
Case 1
strLocation = "='1'"
Case 2
strLocation = "='2'"
End Select
' Build filter string
strFilter = "[StorageRoom] " & strStore & " AND [Location] " & strLocation
' Apply the filter and switch it on
With Reports![LocationsReportbyStorage]
.Filter = strFilter
.FilterOn = True
End With
End Sub