Results 1 to 5 of 5
  1. #1
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23

    Query monthly or yearly using combo boxes

    I'm trying to create query criteria for users where they can return data by either a year or a month and year but no other way using a combo box with the months passing a value 1-12 and a txt box limited to 1000-9999. The txt box for the year is required but the combo box with the months is optional allowing for the entire year. I can get this to work all day using datepart, dateserial, year, or month functions. However, where I run into a problem is getting it to return everything, instead of blank, for the particular year that is in the txt box when the month combo box is left blank. Here is my criteria that works when a value is in the combo box but not when it is blank. Any suggestions on a better way to do this.

    >=Nz(DateSerial([Forms]![Switchboard_Form]![Year],[Forms]![Switchboard_Form]![Month],1),Year([DDRs_Table].[DATEINPUT])=[Forms]![Switchboard_Form]![Year]) And <Nz(DateSerial([Forms]![Switchboard_Form]![Year],[Forms]![Switchboard_Form]![Month]+1,1),([Forms]![Switchboard_Form]![Year])+1)

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I would use 2 ComboBoxes for this:

    cboYear = Year(Now()) 'tblYears as Record Source
    cboMonth = Format(DateSerial(Year(Date()),Month(Date()),Day(D ate())),"mmmm ") 'tblMonths as Record Source
    HTH

  3. #3
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    Quote Originally Posted by burrina View Post
    I would use 2 ComboBoxes for this:



    HTH
    I'm not sure I understand, I'm using the Switchboard_Form unbound, the combo/txt controls on the form are unbound. I'm using those to get the parameters to run a report...I probably didn't explain it well enough. The Report is based on a totals query and the criteria I was talking about is just one column in which the where clause would be used to limit the totals that are returned to only a specified month/year or the entire year.

    So in this one column I am limiting the totals to between the first and last day of the month selected and the year and if the month is null to return the entire year from the Year txt box

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    The Combo Boxes do not need to be bound. I would have a table for months and years respectively. Then refer to the controls on your form in the query the Report is based on.
    Example:
    [Forms]![MyForm]![cboMonth] And [Forms]![MyForm]![cboYear]
    Hope this makes it clearer.

  5. #5
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    Got it to work this is the SQL for the entire query. This is actually pretty easy when you look at the SQL.
    Code:
    SELECT DDRs_Table.PWC, 
    Count([DDRs_Table]![PWC]) AS DDRSLOADED,
     Count([DDRs_Table]![ERRORTYPE].[VALUE]) AS TOTALERRORS,
     Sum(IIf([DDRs_Table]![ERRORTYPE]![Value]="AT",1,Null)) AS [AT],
     Sum(IIf([DDRs_Table]![ERRORTYPE]![Value]="CA",1,Null)) AS CA,
     Sum(IIf([DDRs_Table]![ERRORTYPE]![VALUE]="HMAL",1,Null)) AS HMAL,
     Sum(IIf([DDRs_Table]![ERRORTYPE]![VALUE]="OTHER",1,Null)) AS OTHER,
     Sum(IIf([DDRs_Table]![ERRORTYPE]![VALUE]="TM",1,Null)) AS TM,
     Sum(IIf([DDRs_Table]![ERRORTYPE]![VALUE]="WUC",1,Null)) AS WUC,
     Count(IIf([DDRs_Table]![DDRSTATUS]="ERROR NOT CORRECTABLE",1,Null)) AS UNCORRECTABLEERRORS, 
    Count(IIf([DDRs_Table]![DDRSTATUS]="NOT REVIEWED",1,Null)) AS NOTREVIEWED
    FROM DDRs_Table
    WHERE (((Month([DDRs_Table]![DATEINPUT]))=[Forms]![Switchboard_Form]![Month]) AND ((Year([DDRs_Table].[DATEINPUT]))=[Forms]![Switchboard_Form]![Year])) 
    OR 
    (((Year([DDRs_Table].[DATEINPUT]))=[Forms]![Switchboard_Form]![Year]) AND (([Forms]![Switchboard_Form]![Month]) Is Null))
    GROUP BY DDRs_Table.PWC
    ORDER BY DDRs_Table.PWC;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 08-06-2014, 09:47 AM
  2. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  3. Replies: 2
    Last Post: 03-19-2014, 08:03 PM
  4. Replies: 6
    Last Post: 11-10-2012, 09:49 PM
  5. Combo Boxes Query Criteria help
    By noaccessguru in forum Queries
    Replies: 2
    Last Post: 04-30-2012, 08:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums