seximexi6969
Jun 23 2006, 10:25 AM
I have an advance search form that utilizes queries. Right now I am trying to pinpoint specific data by entering a particular month. My Month filter does not seem to work properly and was wonder if anyone would be able to help.
Below is my code. ::::
DrawingNumberFilter = [Drawing Number Filter]
MonthFilter = [Month Filter]
whereStmnt = ""
'Drawing Number Filter
If DrawingNumberFilter <> "" Then
whereStmnt = "[DrawingNumber Field] like '*" & DrawingNumberFilter & "*'"
End If
'Month Filter
If MonthFilter <> "" Then
If whereStmnt <> "" Then whereStmnt = whereStmnt & " And "
whereStmnt = whereStmnt & "[LastOfWeekEnding] like "MonthFilter/*/year(now())"
End If
If whereStmnt <> "" Then DoCmd.ApplyFilter , whereStmnt
End Sub
dashiellx2000
Jun 23 2006, 10:39 AM
I would do this a little different:
CODE
DrawingNumberFilter = Me.[Drawing Number Filter]
MonthFilter = Me.[Month Filter]
whereStmnt = Null
If IsNull (DrawingNumberFilter) Then
whereStmnt = whereStmnt
Else
whereStmnt = whereStmnt & " AND [DrawingNumber Field] Like '*" & DrawingNumberFilter & "*'"
End if
If IsNull (MonthFilter) Then
whereStmnt = whereStmnt
Else
whereStmnt = whereStmnt & " AND [LastOfWeekEnding] =#" & MonthFilter & "#"
End if
whereStmnt = Mid(whereStmnt, 6)
If Not IsNull(whereStmnt) Then
DoCmd.Apply Filter, whereStmnt
This is untested air code, but should get in going in the right direction.
HTH.
seximexi6969
Jun 23 2006, 11:01 AM
If I use that code than I still get an error. I am trying to pull all of Aprils Data by using a search criteria "April" (or any other month. Currently the "LastOfWeekEnding" is in date formate mm/dd/yyyy. How would I retrive all the records that are populated in April or any month for that matter? The day "dd" and the year "yyyy" can be wild cards if the search.
Edited by: seximexi6969 on Fri Jun 23 12:03:02 EDT 2006.
dashiellx2000
Jun 23 2006, 11:24 AM
So you want the records to be pulled based on month and don't care what day of the month or the year that month fell into. In which case, I'd do:
whereStmnt = whereStmnt & " AND Month([LastOfWeekEnding]) =#" & MonthFilter & "#"
HTH.
seximexi6969
Jun 23 2006, 12:58 PM
That command is giving me this error: Syntax error (missing operator) in query expression 'AND Month([LastOFWeekEnding]) = #July#'
Here's my code for this part:
If MonthFilter <> "" Then
If whereStmnt <> "" Then whereStmnt = whereStmnt & " And "
whereStmnt = whereStmnt & " AND Month([LastOfWeekEnding]) =#" & MonthFilter & "#"
End If
If whereStmnt <> "" Then DoCmd.ApplyFilter , whereStmn
By the way thank you for all your help
dashiellx2000
Jun 23 2006, 01:19 PM
What I think is happening is the Month(LastOfWeekEnding) results in a numberical value for the month (1 - 12) and you have July in your text box. You can either use a combo box to select the month using the bound column for 1 - 12 and the visible column to actually select the month. Or use the MonthName function and remove the # from the string. I personally would use the Combo Box option, then you don't have to worry about users misspelling the month name.
Edited by: dashiellx2000 on Fri Jun 23 14:20:04 EDT 2006.
seximexi6969
Jun 23 2006, 01:24 PM
I have tried that also, But I get the same error. Could there be a problem with this wexpression:
whereStmnt = whereStmnt & " AND Month([LastOfWeekEnding]) =#" & MonthFilter & "#"
Am I missing a bracket() somewhere? should the code be something like...just spectulating...
whereStmnt = whereStmnt & " AND (Month([LastOfWeekEnding]) =#" & MonthFilter & "#")
seximexi6969
Jun 23 2006, 01:31 PM
I got it...with this code:
If MonthFilter <> "" Then
If whereStmnt <> "" Then whereStmnt = whereStmnt & " And "
whereStmnt = whereStmnt & "Month([LastOfWeekEnding]) like '*" & MonthFilter & "*'"
End If
Thanks you so much for your help...you have been a big help....Thanks again for you inputs.
SM
dashiellx2000
Jun 23 2006, 01:36 PM
I see you did get it to work using WildCards, but you should need them. I'm sorry and I forgot to explain that you need to get rid of the # in the string as well for this method.
whereStmnt = whereStmnt & " AND Month([LastOfWeekEnding]) =" & MonthFilter
HTH.
Edited by: dashiellx2000 on Fri Jun 23 14:37:53 EDT 2006.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.