Results 1 to 5 of 5
  1. #1
    mleberso is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    3

    Using a date range with Dcount function


    I am trying to calculate the 2nd pass yield in a text box on my report. The control source is:


    =[rptReworkPass].[Report]![CountOfStatus]/(([rptDailyPaintData].[Report]![AccessTotalsDefect1])-(Nz(DCount("*","tblRework","Status='WIP' And Date=Between [TempVars]![startDate] And [TempVars]![endDate]"),0)))


    This is the number of reworked parts that passed divided by the total number of defects minus the number that are still works in progress. The issue is with date range and tempvar. I have tried this eqn using the general date() formula and it works fine, but I need it to capture data for a specific range that has been stored to a tempvar when the report is opened. I would appreciate any suggestions. It may just be an issue with the syntax. I am using Access 2007.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I think the problem is that "[TempVars]![startDate]" and "[TempVars]![endDate]" cannot be evaluated as dates. They are being seen as text, so when compared to a date, it chokes. Try this:

    Code:
    =[rptReworkPass].[Report]![CountOfStatus]/(([rptDailyPaintData].[Report]![AccessTotalsDefect1])-(Nz(DCount("*","tblRework","[Status] = 'WIP' And [Date] = Between #" & [TempVars]![startDate] & "# And #" & [TempVars]![endDate] & "#),0)))
    ***
    FYI, be aware that "Date" is a reserved word in Access. You shouldn't use reserved words as object names. Also, "Date" is also a function name... using reserved words will cause you headaches and they are not very descriptive. "Date" of what??

    See: Problem names and reserved words in Access

    http://allenbrowne.com/AppIssueBadWord.html
    Last edited by ssanfu; 06-10-2011 at 12:45 AM. Reason: added variable name

  3. #3
    mleberso is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    3
    I tried using the code you gave me, and when I hit enter I reveive an error message saying: "The expression you entered is an invalid string: A string can be up to 2048 characters long, including opening and closing quotation marks." That code is not even close to 2048 characters...any ideas?

  4. #4
    mleberso is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    3
    Never Mind. I just created a query to filter the information by date and did the calculation based on that query. Thank you!

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A good solution! Do you want to use the Thread Tools at the top of the thread and mark this thread as Solved?

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

Similar Threads

  1. Date range
    By eacollie in forum Queries
    Replies: 7
    Last Post: 06-05-2011, 03:38 PM
  2. DCount function problem
    By 10 Gauge in forum Forms
    Replies: 5
    Last Post: 02-28-2011, 02:08 PM
  3. Date Range Parameter help!?!?
    By dkstech in forum Access
    Replies: 1
    Last Post: 01-15-2011, 11:05 AM
  4. Date Range Failure
    By goodguy in forum Queries
    Replies: 4
    Last Post: 12-30-2010, 10:22 AM
  5. Date range help!!
    By bananatodd in forum Access
    Replies: 26
    Last Post: 10-18-2010, 01:57 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