Hi everyone,
Since I started using Access I have made it so far without asking too many questions but now I am stuck and need assistance..
Included in the zip. is a working version of my problem.
My table "EmpTraining" will store 5 fields:
At the point of adding a record to EmpTraining table , EmpID and FleetName_ID and Engine1_ID are Required, Engine2_ID is optional.
I am having trouble generating a Report Filter that will use 3 Listboxes(multiselect) and be able to limit the report by what is selected.
My Listboxes filter:
I am trying to use the Third listbox to filter both Engine1_ID and Engine2_ID and I think this is my main problem.
On the Filter form that has the ListBoxes I use a button to apply the filter to the report, the code for this Onclick event is:
I have tried to change the Build Filter String Section to this with no help:
The only time I get the filter to almost work is when the Build Filter String Section is like this (As you can tell I am only filtering Engine1_ID:
How can I also make it filter the Engine1_ID and Engine2_ID fields .?
Or Should I store the FleetName/Engine1/Engine2 in a different way?
I hope you understand my problem.
Thank you for any help or advice.
Since I started using Access I have made it so far without asking too many questions but now I am stuck and need assistance..
Included in the zip. is a working version of my problem.
My table "EmpTraining" will store 5 fields:
- ID (PK Autonumber )
- EmpID (From Employees Table)
- FleetName_ID ( From FleetList Table )
- Engine1_ID (From EngineList Table )
- Engine2_ID (From EngineList Table )
At the point of adding a record to EmpTraining table , EmpID and FleetName_ID and Engine1_ID are Required, Engine2_ID is optional.
I am having trouble generating a Report Filter that will use 3 Listboxes(multiselect) and be able to limit the report by what is selected.
My Listboxes filter:
- EmpBase (from Employees Table)
- FleetName_ID ( From FleetList Table )
- Engine1_ID (From EngineList Table )
I am trying to use the Third listbox to filter both Engine1_ID and Engine2_ID and I think this is my main problem.
On the Filter form that has the ListBoxes I use a button to apply the filter to the report, the code for this Onclick event is:
Code:
Private Sub btnApplyFilter_Click()
Dim varItem As Variant
Dim strBaseStation As String
Dim strFleetType As String
Dim strEngineType As String
Dim strFilter As String
'Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "TechnicalTrainingReport") <> acObjStateOpen Then
DoCmd.OpenReport "TechnicalTrainingReport", acViewPreview
Exit Sub
End If
' Build criteria string from lstBaseStation listbox
For Each varItem In Me.lstBaseStation.ItemsSelected
strBaseStation = strBaseStation & "," & Me.lstBaseStation.ItemData(varItem)
Next varItem
If Len(strBaseStation) = 0 Then
strBaseStation = "Like '*'"
Else
strBaseStation = Right(strBaseStation, Len(strBaseStation) - 1)
strBaseStation = "IN (" & strBaseStation & ")"
End If
' Build criteria string from lstFleetType listbox
For Each varItem In Me.lstFleetType.ItemsSelected
strFleetType = strFleetType & "," & Me.lstFleetType.ItemData(varItem)
Next varItem
If Len(strFleetType) = 0 Then
strFleetType = "Like '*'"
Else
strFleetType = Right(strFleetType, Len(strFleetType) - 1)
strFleetType = "IN (" & strFleetType & ")"
End If
' Build criteria string from lstEngineType listbox
For Each varItem In Me.lstEngineType.ItemsSelected
strEngineType = strEngineType & "," & Me.lstEngineType.ItemData(varItem)
Next varItem
If Len(strEngineType) = 0 Then
strEngineType = "Like '*'"
Else
strEngineType = Right(strEngineType, Len(strEngineType) - 1)
strEngineType = "IN (" & strEngineType & ")"
End If
' Build filter string
strFilter = "[EmpBase] " & strBaseStation & _
" AND [FleetName_ID] " & strFleetType & _
" AND [Engine1_ID] " & strEngineType & _
" AND [Engine2_ID] " & strEngineType
MsgBox "" & strFilter & "."
' Apply the filter and switch it on
With Reports("TechnicalTrainingReport")
.Filter = strFilter
.FilterOn = True
End With
End Sub
I have tried to change the Build Filter String Section to this with no help:
Code:
' Build filter string
strFilter = "[EmpBase] " & strBaseStation & _
" AND [FleetName_ID] " & strFleetType & _
" AND [Engine1_ID] " & strEngineType & _
" OR [Engine2_ID] " & strEngineType
The only time I get the filter to almost work is when the Build Filter String Section is like this (As you can tell I am only filtering Engine1_ID:
Code:
' Build filter string
strFilter = "[EmpBase] " & strBaseStation & _
" AND [FleetName_ID] " & strFleetType & _
" AND [Engine1_ID] " & strEngineType
' " AND [Engine2_ID] " & strEngineType
How can I also make it filter the Engine1_ID and Engine2_ID fields .?
Or Should I store the FleetName/Engine1/Engine2 in a different way?
I hope you understand my problem.
Thank you for any help or advice.