Sub Search()Dim strCriteria, task As String
If Trim(Me.cboIncomeType.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Please select Payment mode.", buttons:=vbInformation, title:="SOFTWARE"
Me.cboIncomeType.SetFocus
Exit Sub
End If
If Trim(Me.cboIncomeType1.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Please select Payment form.", buttons:=vbInformation, title:="SOFTWARE"
Me.cboIncomeType1.SetFocus
Exit Sub
End If
If IsNull(Me.OrderDateFrom) Then
MsgBox "Please enter the Start date", vbInformation, "Date Range Required"
Me.OrderDateFrom.SetFocus
Else
If IsNull(Me.OrderDateTo) Then
MsgBox "Please enter the End date", vbInformation, "End Date Required"
Me.OrderDateTo.SetFocus
Else
strCriteria = "[DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _
" And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _
" And[PAYMENT_FORM] LIKE '" & IIf(IsNull(Me.cboIncomeType1), "*", Me.cboIncomeType1) & _
" And[PAYMENT_MODE] LIKE '" & IIf(IsNull(Me.cboIncomeType), "*", Me.cboIncomeType) & "'"
'task = "select * from PAY_FORM_ALL_EXPENSE where (" & strCriteria & ") order by [DATE]" )
docmd.applyfilter, strCriteria
end if
end if
Thats the filter code I used which isn’t yielding the results I wantCode:Sub Search()Dim strCriteria, task As String If Trim(Me.cboIncomeType.Value & vbNullString) = vbNullString Then MsgBox prompt:="Please select Payment mode.", buttons:=vbInformation, title:="SOFTWARE" Me.cboIncomeType.SetFocus Exit Sub End If If Trim(Me.cboIncomeType1.Value & vbNullString) = vbNullString Then MsgBox prompt:="Please select Payment form.", buttons:=vbInformation, title:="SOFTWARE" Me.cboIncomeType1.SetFocus Exit Sub End If If IsNull(Me.OrderDateFrom) Then MsgBox "Please enter the Start date", vbInformation, "Date Range Required" Me.OrderDateFrom.SetFocus Else If IsNull(Me.OrderDateTo) Then MsgBox "Please enter the End date", vbInformation, "End Date Required" Me.OrderDateTo.SetFocus Else strCriteria = "[DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _ " And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _ " And[PAYMENT_FORM] LIKE '" & IIf(IsNull(Me.cboIncomeType1), "*", Me.cboIncomeType1) & _ " And[PAYMENT_MODE] LIKE '" & IIf(IsNull(Me.cboIncomeType), "*", Me.cboIncomeType) & "'" 'task = "select * from PAY_FORM_ALL_EXPENSE where (" & strCriteria & ") order by [DATE]" ) docmd.applyfilter, strCriteria end if end if
YesAm having a database which I have a difficulty filtering data in a multiple criteria.
Attached is a sample copy of my database with the issue for analysis.
Any help with this will be highly appreciated
Else
strCriteria = "[DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _
" And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _
" And [PAYMENT_FORM] = '" & Me.cboIncomeType1 & "'" & _
" And [PAYMENT_MODE] = '" & Me.cboIncomeType & "'"
So say you do not know how to debug.print or walk through the code.Yes
I did cross post as you said. Sorry about that.
Needed quick response because I don’t understand the debug print procedure so making it difficult to do that.
And it seemed the help wasnt coming as expected so needed to post here too.
Maybe someone might be of help.
Whatever your reason for cross-posting it is still considered by many to be good practice to post a link to the other post(s)Yes
I did cross post as you said. Sorry about that.
Needed quick response because I don’t understand the debug print procedure so making it difficult to do that.
And it seemed the help wasnt coming as expected so needed to post here too.
Maybe someone might be of help.
My issue is from the strCriteria. The section for the date is finesorry to be critical, but you don't make it easy for people to help - do you not use indenting? What result do you want? what result do you get?
other observations -
1. Date is a reserved word (it is a function that returns today) and should not be used as a field name
2. [DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _
" And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _
could be expressed as
[DATE] between " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _
" And " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _
3. If [DATE] includes a time element, any records with a date of Me.OrderDateTo will not be returned
Did you try the code that I offered in post #7My issue is from the strCriteria. The section for the date is fine
Have tried thisWhy not simply use:
I see no need for using LIKE or IIF as your other code compels users to make a selection in the combo boxesCode:Else strCriteria = "[DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _ " And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _ " And [PAYMENT_FORM] = '" & Me.cboIncomeType1 & "'" & _ " And [PAYMENT_MODE] = '" & Me.cboIncomeType & "'"
Perhaps you should check that you copied and pasted it correctly (as I have just done) because it compiles fine in the db that you postedHav
Have tried this
But the code turns red and doesn’t compile
rechecked and noticed I didn’t copy it properlyPerhaps you should check that you copied and pasted it correctly (as I have just done) because it compiles fine in the db that you posted
Glad you have a solution. I hope you'll take the time to read the link that I posted about cross-posting.I
rechecked and noticed I didn’t copy it properly
And yes
Your suggestion helped fixed the issue for me
Thanks a lot
Will do thatGlad you have a solution. I hope you'll take the time to read the link that I posted about cross-posting.