UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Advance Search Help    
 
   
seximexi6969
post Jun 23 2006, 10:25 AM
Post #1

New Member
Posts: 17



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
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 8)
dashiellx2000
post Jun 23 2006, 10:39 AM
Post #2

UtterAccess VIP
Posts: 9,209
From: Maryland



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.
Go to the top of the page
 
+
seximexi6969
post Jun 23 2006, 11:01 AM
Post #3

New Member
Posts: 17



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.
Go to the top of the page
 
+
dashiellx2000
post Jun 23 2006, 11:24 AM
Post #4

UtterAccess VIP
Posts: 9,209
From: Maryland



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.
Go to the top of the page
 
+
seximexi6969
post Jun 23 2006, 12:58 PM
Post #5

New Member
Posts: 17



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
Go to the top of the page
 
+
dashiellx2000
post Jun 23 2006, 01:19 PM
Post #6

UtterAccess VIP
Posts: 9,209
From: Maryland



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.
Go to the top of the page
 
+
seximexi6969
post Jun 23 2006, 01:24 PM
Post #7

New Member
Posts: 17



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 & "#")
Go to the top of the page
 
+
seximexi6969
post Jun 23 2006, 01:31 PM
Post #8

New Member
Posts: 17



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
Go to the top of the page
 
+
dashiellx2000
post Jun 23 2006, 01:36 PM
Post #9

UtterAccess VIP
Posts: 9,209
From: Maryland



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.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 03:02 AM