Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    121

    Unanswered: Printing using dates and times as criteria

    Hello all,
    This one should be simple for someone. I have a database to create shipping bills of lading. Trailers will be entered into the table and and ship date field filled in and a release time field filled in. There will also be a field to indicate how many hours early a trailer can be picked up from the release time (say 3 hours, 6 hours, etc.).

    When I print the bill of lading, I will use a form to pull up the record I want to print and check for information being complete. When I press the print button, I want the action to before printing do an If/Then command that would check to see If the release date, release time and the release time minus the early pickup time allotment are within the current time. I.e., if a load to leave on the 15th at 6:00 am with a 3 hour early pickup indicated, will print as long as the current time is 3:00 am or after on the 15th. If not, I need an error message to tell the gatehouse guard that it's too early to release the load.

    Any suggestions?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    looks as though you are using separate date datetimes and time datetimes to store your data.

    dim bothDT as date 'combined date time
    bothDT = ShipDate + ReleaseTime 'cheating, but it works in A (see later)
    if datediff("h", bothDT, Now()) > EarlyHoursPermitted then
    msgbox "Too early"
    else
    '----------print here
    endif

    the 'official' approach to combine the two datetimes:
    bothDT = dateadd("h", hour(ReleaseTime), ShipDate)
    NB Hour() rounds down to integer hours... hour(6:45) = 6
    if you have partial hours you will also need
    bothDT = dateadd("n", minute(ReleaseTime), ShipDate) 'ennn is not a typo

    ...this stuff will 'roll over backwards' if you see what i mean. 6am allowed 9 hours early will be 9pm one day back (which makes sense but might not be what you want).

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Dec 2005
    Posts
    121
    Thanks for the help Izy!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •