Query based on month of record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeadooRider
    New Member
    • Jan 2013
    • 48

    Query based on month of record

    If all my records have a date on them for when they were entered, how can I create a query that will pull those records entered within a selected month/year?
    Using of course a combobox for the user to select the month/year, or a calendar box.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    If you are just looking for the month and year, then you would need to use a combination of the Year(), Month() and possibly MonthName() functions. Lets say your date field is called DateEntered and you have cboMonth and cboYear for your combo boxes. If your months combo box is tied to a number (the number of the month, ie. 1 = January, 7 = July, etc.) then your WHERE clause of your query would look something like this:
    Code:
    WHERE Year(DateEntered) = cboYear
    AND Month(DateEntered) = cboMonth
    If your month combo box is just a list of names, then your WHERE clause would look something like this:
    Code:
    WHERE Year(DateEntered) = cboYear
    AND MonthName(Month(DateEntered)) = cboMonth

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32662

      #3
      Your WHERE clause would be similar to :
      Code:
      WHERE (Format([DateField],'yyyymm')=Forms!FormName!ControlName)

      Comment

      Working...