Djblois
06-08-2011, 07:05 AM
I use 11 queries for one form for the different choices that a user selects. I want to however try to combine them to 1 query if possible. Here are the 11 queries:
I have posted the form for people to look at the queries.
The issue is that I have 3 separate sets of checkboxes that affect the queries.
Set 1 - Has 2 checkboxes, user chooses if he wants to view Receiving appts or Shipping appts or both
- This one is easy to manipulate because Shipping and Receiving are two separate Yes/No fields in the database.
((Scheduled_Appts.Incoming)=[Forms]![frmScheduled_Appts]![cbViewRec]) AND (Scheduled_Appts.Outgoing)=[Forms]![frmScheduled_Appts]![cbViewShip])Set 2 - Has 1 checkbox, user chooses if they want to see Completed appts or not. (non-completed appts are always shown in the queries)
- This is determined by if the Date Completed Field is null or not. If it is null then it is not completed.
- This has caused me to double the amount of queries I have. I cannot figure out how to filter by a null field if it is Not checked but then do not filter if it is checked.
((Scheduled_Appts.Dep_Time) Is Null)Set 3 - Has 3 checkboxes, user chooses if they want to view Whse 1, Whse 2, Whse 3, or a combination of them
- This is determined by one field that tells what Whse the appt is out of.
- This is easy when it is only one Whse:
((Scheduled_Appts.WhseID)=getWhse()))
Function getWhse() As String
getWhse = GetSetting("WST", "General", "Whse")
End Function
If Me.cb01 Then SaveSetting "WST", "General", "Whse", 1- It is not easy when it is two or more Whses, I change the Query instead:
Private Sub ChooseView()
On Error GoTo err_handler
If (Not Me.cbViewRec And Not Me.cbViewShip) Or (Not Me.cb01 And Not Me.cb02 And Not Me.cbDemed) Then
enableDisableFields False
Else
On Error Resume Next
If Me.cb01 And Me.cb02 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&2&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&2&3"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 And Me.cb02 Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&2"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&2"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&3"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 Then
If DLookup("[AtReports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 1
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[AtApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
ElseIf Me.cb02 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts2&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted2&3"
End If
If DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb02 Then
If DLookup("[02Reports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 2
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[02ApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
ElseIf Me.cbDemed Then
If DLookup("[DeReports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 3
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[DeApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
Else
enableDisableFields False
Me.cmdPrintReports.Enabled = False
Exit Sub
End If
enableDisableFields True
End If
If Form_SubfrmAppts.AllowEdits Then
Me.cbInputTime.Visible = True
Else
Me.cbInputTime.Visible = False
End If
Exit Sub
End Sub
This is adding a lot of unnecessary code and Queries. Please help me reduce this. I know this is a big job and anyone that can help me fix this - I would be willing to pay them through paypal for their time. My goal is to get it down to 1 query if possible if not as few as possible.
I have posted the form for people to look at the queries.
The issue is that I have 3 separate sets of checkboxes that affect the queries.
Set 1 - Has 2 checkboxes, user chooses if he wants to view Receiving appts or Shipping appts or both
- This one is easy to manipulate because Shipping and Receiving are two separate Yes/No fields in the database.
((Scheduled_Appts.Incoming)=[Forms]![frmScheduled_Appts]![cbViewRec]) AND (Scheduled_Appts.Outgoing)=[Forms]![frmScheduled_Appts]![cbViewShip])Set 2 - Has 1 checkbox, user chooses if they want to see Completed appts or not. (non-completed appts are always shown in the queries)
- This is determined by if the Date Completed Field is null or not. If it is null then it is not completed.
- This has caused me to double the amount of queries I have. I cannot figure out how to filter by a null field if it is Not checked but then do not filter if it is checked.
((Scheduled_Appts.Dep_Time) Is Null)Set 3 - Has 3 checkboxes, user chooses if they want to view Whse 1, Whse 2, Whse 3, or a combination of them
- This is determined by one field that tells what Whse the appt is out of.
- This is easy when it is only one Whse:
((Scheduled_Appts.WhseID)=getWhse()))
Function getWhse() As String
getWhse = GetSetting("WST", "General", "Whse")
End Function
If Me.cb01 Then SaveSetting "WST", "General", "Whse", 1- It is not easy when it is two or more Whses, I change the Query instead:
Private Sub ChooseView()
On Error GoTo err_handler
If (Not Me.cbViewRec And Not Me.cbViewShip) Or (Not Me.cb01 And Not Me.cb02 And Not Me.cbDemed) Then
enableDisableFields False
Else
On Error Resume Next
If Me.cb01 And Me.cb02 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&2&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&2&3"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 And Me.cb02 Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&2"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&2"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts1&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted1&3"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb01 Then
If DLookup("[AtReports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 1
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[AtOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[AtApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
ElseIf Me.cb02 And Me.cbDemed Then
Me.cmdPrintReports.Enabled = False
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryAppts2&3"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompleted2&3"
End If
If DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True And _
DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
ApptEditingAbility False
ElseIf Me.cb02 Then
If DLookup("[02Reports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 2
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[02OrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[02ApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
ElseIf Me.cbDemed Then
If DLookup("[DeReports]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
Me.cmdPrintReports.Enabled = True
Else
Me.cmdPrintReports.Enabled = False
End If
SaveSetting "WST", "General", "Whse", 3
If Me.cbCompleted Then
Form_SubfrmAppts.RecordSource = "qryApptsOneWhse"
Else
Form_SubfrmAppts.RecordSource = "qryNotCompletedOneWhse"
End If
If DLookup("[DeOrdersEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
OrderEditingAbility True
Else
OrderEditingAbility False
End If
If DLookup("[DeApptsEdit]", "tblRoles", "[Roles] = '" & strGroupPolicy & "'") = True Then
ApptEditingAbility True
Else
ApptEditingAbility False
End If
Else
enableDisableFields False
Me.cmdPrintReports.Enabled = False
Exit Sub
End If
enableDisableFields True
End If
If Form_SubfrmAppts.AllowEdits Then
Me.cbInputTime.Visible = True
Else
Me.cbInputTime.Visible = False
End If
Exit Sub
End Sub
This is adding a lot of unnecessary code and Queries. Please help me reduce this. I know this is a big job and anyone that can help me fix this - I would be willing to pay them through paypal for their time. My goal is to get it down to 1 query if possible if not as few as possible.