Code:
Private Sub cboStatus_AfterUpdate()
Call SearchCriteria("[ReportID]")
End Sub
Private Sub cboType_AfterUpdate()
Call SearchCriteria("[ReportID]")
End Sub
Function SearchCriteria(myString As String)
Dim strSOReportNo As String, strStaName As String, strTypeID As String, strSalesOrg As String
Dim strActDate As String, strActfDate As String, strActtDate As String, strActftDate As String
Dim task As String, strCriteria As String
If IsNull(Me.cboSOReportNo) Then
strSOReportNo = "[SOReportNo] like '*'"
Else
strSOReportNo = "[SOReportNo] = '" & Me.cboSOReportNo & "'"
End If
If IsNull(Me.cboStatus) Then
strStaName = "[StatusName] like '*'"
Else
strStaName = "[StatusName] = '" & Me.cboStatus & "'"
End If
If IsNull(Me.cboType) Then
strTypeID = "[TypeID] like '*'"
Else
strTypeID = "[TypeID] = " & Me.cboType
End If
If IsNull(Me.cboActionDate) Then
strActDate = "[ActionDate] like '*'"
Else
strActDate = "[ActionDate] = #" & Format(Me.cboActionDate, "mm\/dd\/yyyy") & "#"
End If
If IsNull(Me.cboActionfDate) Or IsNull(Me.cboActiontDate) Then
'strActfDate = "[ActionDate] like '*'"
strActfDate = "[ActionDate] = #" & Format(Me.cboActiontDate, "mm\/dd\/yyyy") & "#"
strActtDate = "[ActionDate] like '*'"
strActftDate = "[ActionDate] like '*'"
Else
strActftDate = "[ActionDate] BETWEEN #" & Format(Me.cboActionfDate, "mm\/dd\/yyyy") & "# AND #" & Format(Me.cboActiontDate, "mm\/dd\/yyyy") & "#"
End If
If IsNull(Me.cboSalesOrg) Then
strSalesOrg = "[SOrgID] like '*'"
Else
strSalesOrg = "[SOrgID] = " & Me.cboSalesOrg
End If
'myString = "[ReportID]"
'strActDate & " AND " &
strCriteria = strSOReportNo & " AND " & strStaName & " AND " & strTypeID & " AND " & _
strActDate & " AND " & strSalesOrg & " AND " & strActftDate
task = "SELECT * FROM tblReport WHERE " & strCriteria & " ORDER BY " & myString
Me.subfrmReport.Form.RecordSource = task
Me.subfrmReport.Form.Requery
End Function