I have what I am going to call a chain query that works, however I believe there is a more concise and clear way to write it out.
Here is what I want and how it works.
The form where the query is essentially defaults to all records. There are three filter values that a user can choose from, vProgram, vVehicle, and vAttribute. At form open all records will be displayed, that is all program, vehicles and attributes. The query below does this correctly.
From the top down it will sort:
Program (all) -> Vehicle (all) -> Attribute (all)
Program (all) -> Vehicle (all) -> Attribute (single)
Program (single) -> Vehicle (all) -> Attribute (all)
Program (single) -> Vehicle (all) -> Attribute (single)
Program (single) -> Vehicle (single) -> Attribute (all)
Program (single) -> Vehicle (single) -> Attribute (single)
Is there a better way to do this?
Hopefully this is clear and I appreciate any and all help.
Here is what I want and how it works.
The form where the query is essentially defaults to all records. There are three filter values that a user can choose from, vProgram, vVehicle, and vAttribute. At form open all records will be displayed, that is all program, vehicles and attributes. The query below does this correctly.
From the top down it will sort:
Program (all) -> Vehicle (all) -> Attribute (all)
Program (all) -> Vehicle (all) -> Attribute (single)
Program (single) -> Vehicle (all) -> Attribute (all)
Program (single) -> Vehicle (all) -> Attribute (single)
Program (single) -> Vehicle (single) -> Attribute (all)
Program (single) -> Vehicle (single) -> Attribute (single)
Is there a better way to do this?
Code:
If Me.cboFilterProgram = gciProgramAllID Then
If Me.cboFilterAttribute = "All" Then
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"FROM tblPlan " & _
"ORDER BY PlanStart;"
Else
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"From tblPlan " & _
"WHERE PlanAttribute = " & QUOTE & Me.cboFilterAttribute & QUOTE & "ORDER BY PlanStart;"
End If
Else
If Me.cboFilterVehicle = "All" Then
If Me.cboFilterAttribute = "All" Then
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"From tblPlan " & _
"WHERE PlanProgramNumberID = " & Me.cboFilterProgram & "ORDER BY PlanStart;"
Else
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"From tblPlan " & _
"WHERE PlanProgramNumberID = " & Me.cboFilterProgram & " AND " & _
"PlanAttribute = " & QUOTE & Me.cboFilterAttribute & QUOTE & "ORDER BY PlanStart;"
End If
Else
If Me.cboFilterAttribute = "All" Then
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"From tblPlan " & _
"WHERE PlanProgramNumberID = " & Me.cboFilterProgram & " AND " & _
"PlanVehicleID = " & QUOTE & Me.cboFilterVehicle & QUOTE & "ORDER BY PlanStart;"
Else
Me.lstAppointments.RowSource = "SELECT tblPlan.PlanID, tblPlan.PlanVehicleID, tblPlan.PlanAttribute, " & _
"DateValue([PlanStart]) AS [AS], DateValue([PlanEnd]) AS AE, tblPlan.PlanEngineer, tblPlan.PlanProgramNumberID, tblPlan.PlanStart " & _
"From tblPlan " & _
"WHERE PlanProgramNumberID = " & Me.cboFilterProgram & " AND " & _
"PlanVehicleID = " & QUOTE & Me.cboFilterVehicle & QUOTE & " AND " & _
"PlanAttribute = " & QUOTE & Me.cboFilterAttribute & QUOTE & "ORDER BY PlanStart;"
End If
End If
End If
Hopefully this is clear and I appreciate any and all help.