Results 1 to 4 of 4
  1. #1
    rookie77 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    4

    Question Need help with Expression in Query


    I have an existing query for 12 month order history. In the criteria it asks for the number of months therefore when the report is ran, you are prompted to enter the number of months you are inquiring about. Now I need to create a calculation based upon that entry. So if I was to run the report for a 3 month period I want the calculations based upon sales for month 1 through 3. But if I was to run the report for a 5 month period I want the calculations based upon sales for month 1 through 5. And so on. I'm just learning Access and don't have these figured out quite yet. Any assistance would be appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Look at the DateAdd function
    see http://www.techonthenet.com/access/f...te/dateadd.php There are other date functions there also Month, Year

    You might use something like this (untested)

    Let's suppose the user types into a field called intField, and suppose he types in 7.

    Your query for the report would be along these lines

    Select yourdata from yourtable
    where Month(SalesDate) Between 1 and intField

  3. #3
    rookie77 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    4
    I don't think that approach will work in my case simply because its not an actual 'date' per say with a year and month and all that. The way it works is Demand 1 is always always the 'current' month. The previous month is always demand 2 and the month prior to that is always demand 3 and so on. So, I could be wrong but I don't think the dateadd function would work here. I'm working with a report and query that was created by someone else and am attempting to make one change to get the correct results. In the criteria it shows >=[> = 12 Month Demand?] which in turn prompts you when running the report to select how many months you want to run. So I'm trying to find a way to use whatever is entered there to determine what the report shows. In my mind I'm thinking it should be like an if statement probably something like if 3 then demand 1 + demand 2 + demand 3. I'm just not educated enough in access quite yet to determine the proper way to structure this for it to work correctly.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    The DateAdd was just a thought for adding a month or x months to a date (todays date).

    Did you see my select query's where clause. I think that is more along the lines of what you want.
    You will need some logic to relate your demand1, demand2 etc to an actual month range (I think).

    I also think you might have a form. The form would be used to capture the demand info, verify the entry, then translate that and build a query with the demand info. Use that query as the recordsource for the Report and then Open that report from a Button on the Form.

    Good luck.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  2. Replies: 4
    Last Post: 10-26-2012, 12:49 AM
  3. Query Expression Help
    By hmartin in forum Queries
    Replies: 7
    Last Post: 01-21-2012, 11:37 PM
  4. Query Expression
    By nizam in forum Queries
    Replies: 1
    Last Post: 11-12-2011, 02:56 PM
  5. Expression for Query Help
    By fikeplay in forum Access
    Replies: 1
    Last Post: 07-09-2011, 05:12 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