Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    But there's no time field or any time stamp on the data you're supplying so what are you supposed to check the time against?

  2. #17
    Bruce is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    72
    The system clock. If the CloseDate = the current date and the system clock indicates >=15:00 return true.

  3. #18
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    So this report is run once per day at exactly 3pm?

    Then if that's the case you wouldn't need the time check at all, you would just assume anything with a closed date was closed prior to 3pm of today's date.

    If you are running it at any time during the day, let's say you run it at 5pm there is no way to tell by your data which items were closed prior to 3pm. You would have to have a time field or set your date/time field to include the hour the item was closed. Artificially adding a 3pm date to anything with a closed date of today really does nothing for your query because you're not actually checking it against anything, the same goes for the lower end (now()-180) you would.

    I don't follow why you need to perform a time check when you are not storing the time, you are creating a time then checking against that time which doesn't make sense to me.

  4. #19
    Bruce is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    72
    I have a "report" window that runs constantly and updates every 5 minutes. It's function is to show orders that have expired starting with the current date and going back 180 days, that need to be manually closed out in the db. When the order is closed out, it does not show up in the query as the status is now "closed". When the db was designed, the time of closure was not a factor "as every order expires at 3:00 p.m. on the CloseDate".
    In the date.db I provided please enter "=open" for the criteria under the "Status" column.
    i.e. If the CloseDate = Date() and the system clock indicates it is 3:00 p.m. or after, the query should return that item. If the CloseDate = Date() and the system clock indicates it is 10:00 a.m. the query should not return that item. Currently it does. Thus my conundrum.

    It's no big deal. Just need to teach the users that if an items shows up needing closure and the CloseDate is the current date, not to close out the item until after 3:00 p.m. It would be better if the item did not show up in the list until after 3:00 p.m.

  5. #20
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Ok, I see now.

    Would you prefer the database to update the open/close flag whenever you enter a close date? that way you wouldn't have to rely on human input. Alternately, you don't need to even save the OPEN/CLOSE flag on the table at all, you can code such that any item with a close date is closed. Is there a reason for having a dual flag (close date and field that literally says 'open' or 'closed')?

    If you would rather do this it can be handled more fairly simply if you have a reason for having two 'open' flags I'll have another go at your query.

  6. #21
    Bruce is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    72
    Great! The reason for the open/close flag is for users to manually confirm they have "also" performed the necessary physical steps to close the order prior to setting the db open/close flag to "closed" which is performed via another form.

    Can you tell me why I can't use the Date() function (in this db) as criteria in the query? The error indicates I have an undefined function. I always thought Date() was a predefined function, like Now().

  7. #22
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Can you tell me why I can't use the Date() function (in this db) as criteria in the query? The error indicates I have an undefined function. I always thought Date() was a predefined function, like Now().
    I have experienced this. Open the VBA window (Control +G). Click on Tools, References. Check to see if any items listed are indicated as missing. If so, scroll down until you find the missing reference and click it. Update the references and close the VBA window.

    Alan

  8. #23
    Bruce is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    72
    Quote Originally Posted by alansidman View Post
    I have experienced this. Open the VBA window (Control +G). Click on Tools, References. Check to see if any items listed are indicated as missing. If so, scroll down until you find the missing reference and click it. Update the references and close the VBA window.

    Alan
    Thanks, I did what you mentioned but there are many "unchecked" references. I'm not sure what you mean by "find the missing reference".

  9. #24
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    A reference that is needed that is not checked will be marked with the term "Missing." If you have searched and not found this, then it is another issue. I am not sure what is the cause is to create this. You might want to create a new thread with this issue so that it gains some attention. Be sure to make your title clear.

    Alan

  10. #25
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    These are the references I have and the date() function works in queries

    Visual Basic for Applications
    Microsoft Access 12.0 Object Library
    OLE Automation
    Microsoft Office 12.0 Access Database engine Objects

    (this is on a 2007 machine your versions may be 11.0?)

    I'm working on the query will post it later.

    Hrm this is weird I set up identical references in your database and the date() function still does not work, may have to use a different reference for earlier versions of MS access.

  11. #26
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Try using this query:

    Code:
    SELECT WorkOrders.WorkOrderID, WorkOrders.OpenDate, WorkOrders.CloseDate, WorkOrders.Status, Now() AS CurrentTime
    FROM WorkOrders
    WHERE (((WorkOrders.CloseDate)<Format(Now(),"Short Date")) AND ((WorkOrders.Status)="open")) OR (((WorkOrders.CloseDate)=Format(Now(),"Short Date")) AND ((WorkOrders.Status)="open") AND ((Now())>CDate(Format(Now(),"Short Date") & " 03:00:00 PM")));
    I put everything in terms of now() so it shouldn't cause you any grief if you can't get the references working.

  12. #27
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    On the Date() function not working: I found this unusual. I tried it out on two different machines, one with Access XP and one with Access 2007. Both indicated undefined function. I then created a new db and imported the table and query to the new db. Changed Now() to Date() in the query and it works. I think that you might have something corrupted in your db. You can always import to a new db and give it a try. Still not sure what the cause was.

    Alan

  13. #28
    Bruce is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    72
    I fixed this one. I added the expression Hour(Now()) which provided the system clock hour, I then set the criteria to >=15 and it works!

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-13-2011, 11:00 AM
  2. query criteria for current date
    By Paul-NY in forum Queries
    Replies: 5
    Last Post: 07-05-2011, 02:21 PM
  3. Criteria for date due
    By Desstro in forum Queries
    Replies: 4
    Last Post: 11-30-2010, 12:54 PM
  4. Query Date Criteria
    By svanicek in forum Access
    Replies: 1
    Last Post: 07-09-2010, 11:13 AM
  5. Query criteria, add 5 months to date
    By thart21 in forum Queries
    Replies: 1
    Last Post: 03-29-2010, 05: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