Results 1 to 14 of 14
  1. #1
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36

    Criteria help

    I have this code that moves the 3rd shift start date ahead 1 day because they start at 10pm the previous date, I need to add to it so if they transact on between midnight and 7am it doesn't move the date ahead. The column name for the time is [Time On] any ideas?
    Code:
    IIf([shift]=3,[date]+1,[date])
    thanks
    JC

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What is the [Time On] datataype - text or date? Show sample value - 24hr or AM/PM?

    Maybe something like:

    IIf([shift]=3 And [Time On] > 700 And [Time On] < 2400, [date]+1, [date])

    Getting the time values right is the trick.

  3. #3
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    June7,

    Thanks for your response, the datatype is Date/Time formatted as Medium Time. I will work with tyour suggestion today.

    Thanks JC

  4. #4
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    June7

    This appears to be working perfectly thank you for your help. Have a great day.

  5. #5
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    Well spoke to soon, looks like it is not working as I thought, it may be a format thing like you said. If I look in the table the time looks like this "5/3/2011 10:00:21 PM", even if I type 22:00 into the table with a 3 for shift it does not seem to matter. The [Time On] field has a datatype of Date/Time. any other suggestions?
    Code:
    IIf([shift]=3 And [Time On]>7 And [Time On]<24,[date]+1,[date])

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Extract the time part from datetime and compare with criteria. Test this out:

    Format([Time On], "hh") > 7 AND Format([Time On], "hh") < 24

  7. #7
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    June7,

    Thanks again for your help, I am not sure how to do what you are suggesting here is what I changed it to but it does not work. I don't think I am doing what you are suggesting correctly.

    Code:
    IIf([shift]=3 And Format([Time On], "hh") > 7 AND Format([Time On], "hh") < 24 )

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Well, what you show is not the entire expression, which should be:
    IIf([shift]=3 And Format([Time On], "hh") > 7 AND Format([Time On], "hh") < 24, date]+1, [date])

    Is this what you actually have? If it is and still not working, what is the error - a message, wrong results, nothing?

  9. #9
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    June7,

    The error reads "The expression you entered contains invalid syntax" "You omitted an operand or operator, you entered an invalid character or comma, or you entered text without surrounding it in quotations marks"

  10. #10
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    Ok I found why I got that error but now I am getting this error,

    "The expression IIf([shift]=3 And Format([Time On], "hh") > 7 AND Format([Time On], "hh") < 24, [date]+1, [date]) cannot be used in a calculated column.

    Code:
    IIf([shift]=3 And Format([Time On], "hh") > 7 AND Format([Time On], "hh") < 24, [date]+1, [date])

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I tested that expression in the Immediate window of VBA editor. So now tested in query designer. Doesn't like the quote marks, had to change to apostrophes. It worked but was a simiple Select query. Suggest you try that first and when you get that working try it in your final query. If still doesn't work for you will need to see your query statement for analysis. Don't think ever encountered that error msg.

  12. #12
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    Ok thanks for your help, I am using this expression in a table using hte calculated option but even after changing the quote marks I still get the error "cannot be used in a calculated column"

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I was assuming you were building a query and sounds like you will have to. I have never done a 'calculated column' in table. Must be new to Access2010.

    Build query and use the calculated field to construct field in query with the expression.

  14. #14
    jcaptchaos2 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    36
    Thanks for all your help, will give it a try tomorrow at work

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

Similar Threads

  1. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 PM
  2. >Date() criteria
    By BED in forum Queries
    Replies: 3
    Last Post: 12-15-2010, 03:29 AM
  3. Query Criteria
    By sbrookebounds in forum Access
    Replies: 0
    Last Post: 12-08-2010, 03:07 PM
  4. Query Criteria
    By MrMitch in forum Queries
    Replies: 0
    Last Post: 03-31-2009, 02:25 PM
  5. Variable Criteria
    By JamesLens in forum Queries
    Replies: 0
    Last Post: 01-02-2009, 04:55 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