Query by form with different textbox criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abadaysheker2
    New Member
    • May 2014
    • 7

    Query by form with different textbox criteria

    Hi

    i had a form (form2) with a listbox that displays the numbers from 1-12(representing the number of month) and a txtbox on which the user enters the year.

    now i want to run a query with the criteria taken from this form ,that displays all the orders in the case of both listbox and txtbox are blank. in case that the user fills only the listbox(months) display all the orders that were made in that month at every year and finally in the case that he only fills the textbox(year) display all of the orders of that year

    so far i have managed to make it work with the listbox (month)selected and both (listbox and textbox) blank but with regards to the textbox(year) i hasn't be able to make it work

    any help will be appreciated

    for more details i leave here the sql code an a picture of how it looks the query

    thank you

    Code:
     SELECT orders.[or-id], Sum([quantity_x_price_qry(help)].subtotal) AS SumOfsubtotal, orders.DateEntered, Month([orders]![DateEntered]) AS jodesh, Year([orders]![DateEntered]) AS shana, customers.FirstName, customers.LastName
    FROM customers INNER JOIN ([quantity_x_price_qry(help)] INNER JOIN orders ON [quantity_x_price_qry(help)].[or-id] = orders.[or-id]) ON customers.[cust-id] = orders.[cust-id]
    GROUP BY orders.[or-id], orders.DateEntered, Month([orders]![DateEntered]), Year([orders]![DateEntered]), customers.FirstName, customers.LastName
    HAVING (((Month([orders]![DateEntered]))=[Forms]![Form2]![Monthtxt] Or [Forms]![Form2]![Monthtxt] Is Null) AND ((Year([orders]![DateEntered]))=[Forms]![Form2]![YearTxt] Or [Forms]![Form2]![YearTxt] Is Null));
    [imgnothumb]http://bytes.com/attachment.php? attachmentid=77 44[/imgnothumb]
    Attached Files
    Last edited by zmbd; Aug 4 '14, 09:34 PM. Reason: [Z{Made attached images visable}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    See if one of these will point you in the right direction...
    Don't worry if you don't understand the code, we'll help you thru it, just let us know where you get stuck:
    -filtering-

    Comment

    Working...