Hi All,
I have a dynamic query (below). I would like to add one more criteria to the where clause... but it is a combination of 2 different criteria in one and I'm drawing a blank as to how to do it.
How can I add the 2 criteria so that they are not taken individually
I want:
If StatusID = 2 AND DateField > SomeDate then include in query result set
I do not want
If StatusID = 2 the include in query result set
AND if DateField > SomeDate then include in query result set
I hope this makes sense and further that this is an easy question and I'm just not seeing it.
Thanks, as always, in advance.
' Build a dynamic query based on the forms input
If Not IsNull(Me![SiteID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.SiteID]= " & Me![SiteID]
End If
If Me.PriorityID.ItemsSelected.Count > 0 Then
For Each varItem In Me.PriorityID.ItemsSelected
strListPriority = strListPriority & Me.PriorityID.ItemData(varItem) & " , "
Next varItem
Xwhere = Xwhere & " AND [tblIssueIncident.PriorityID] IN(" & strListPriority & "99) "
End If
If Me.StatusID.ItemsSelected.Count > 0 Then
For Each varItem In Me.StatusID.ItemsSelected
strListStatus = strListStatus & Me.StatusID.ItemData(varItem) & " , "
Next varItem
Xwhere = Xwhere & " AND [tblIssueIncident.StatusID] IN(" & strListStatus & "99) "
If Not IsNull(Me![IncidentMIGDeptID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentMIGDeptID]= " _
& Me![IncidentMIGDeptID]
End If
If Not IsNull(Me![IncidentMIGDeptContactID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentMIGDeptContactID]= " _
& Me![IncidentMIGDeptContactID]
End If
If Not IsNull(Me![IncidentSiteContactID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentSiteContactID]= " _
& Me![IncidentSiteContactID]
End If
Set QD = db.CreateQueryDef("Dynamic_Query", _
"Select * from tblIssueIncident INNER JOIN tblIssueUpdate ON " _
& "tblIssueIncident.MyIssueIncidentID=tblIssueUpdate.IssueIncidentID" _
& (" where " + Mid(Xwhere, 6) & ";"))
I have a dynamic query (below). I would like to add one more criteria to the where clause... but it is a combination of 2 different criteria in one and I'm drawing a blank as to how to do it.
How can I add the 2 criteria so that they are not taken individually
I want:
If StatusID = 2 AND DateField > SomeDate then include in query result set
I do not want
If StatusID = 2 the include in query result set
AND if DateField > SomeDate then include in query result set
I hope this makes sense and further that this is an easy question and I'm just not seeing it.
Thanks, as always, in advance.
' Build a dynamic query based on the forms input
If Not IsNull(Me![SiteID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.SiteID]= " & Me![SiteID]
End If
If Me.PriorityID.ItemsSelected.Count > 0 Then
For Each varItem In Me.PriorityID.ItemsSelected
strListPriority = strListPriority & Me.PriorityID.ItemData(varItem) & " , "
Next varItem
Xwhere = Xwhere & " AND [tblIssueIncident.PriorityID] IN(" & strListPriority & "99) "
End If
If Me.StatusID.ItemsSelected.Count > 0 Then
For Each varItem In Me.StatusID.ItemsSelected
strListStatus = strListStatus & Me.StatusID.ItemData(varItem) & " , "
Next varItem
Xwhere = Xwhere & " AND [tblIssueIncident.StatusID] IN(" & strListStatus & "99) "
If Not IsNull(Me![IncidentMIGDeptID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentMIGDeptID]= " _
& Me![IncidentMIGDeptID]
End If
If Not IsNull(Me![IncidentMIGDeptContactID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentMIGDeptContactID]= " _
& Me![IncidentMIGDeptContactID]
End If
If Not IsNull(Me![IncidentSiteContactID]) Then
Xwhere = Xwhere & " AND [tblIssueIncident.IncidentSiteContactID]= " _
& Me![IncidentSiteContactID]
End If
Set QD = db.CreateQueryDef("Dynamic_Query", _
"Select * from tblIssueIncident INNER JOIN tblIssueUpdate ON " _
& "tblIssueIncident.MyIssueIncidentID=tblIssueUpdate.IssueIncidentID" _
& (" where " + Mid(Xwhere, 6) & ";"))