Results 1 to 5 of 5
  1. #1
    Elin is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Sep 2014
    Posts
    3

    Question Use Cdate and write yesterday's date?

    Hi!
    Background: We have shifts working from 23h00 to 06h00. However I would like to add a column with the Starting date of the shift, to be able to sort on that in reports.

    SID - Shift ID


    StartDatum = start of shift
    DatumTid = time stamp of record

    Code:
     
        Dim szTime As String
     
        szTime = Time
     
                If (MyRs![SID] = 3 Or MyRs![SID] = 5 Or MyRs![SID] = 6) _
                    And (TimeValue(szTime) > "00:00:00" Or TimeValue(szTime) < "17:00:00") Then
                    
                    MyRs![StartDatum] = CDate(MyRs![DatumTid]) - 1
                ElseIf (MyRs![SID] <> 3 Or MyRs![SID] <> 5 Or MyRs![SID] <> 6) Then
                    MyRs![StartDatum] = CDate(MyRs![DatumTid])
                    
                End If
    Why does it not work? What to do to make it work?
    I always get StartDatum = DatumTid

    Thanks for help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I think
    (MyRs![SID] <> 3 Or MyRs![SID] <> 5 Or MyRs![SID] <> 6) Then

    needs to be AND...
    (MyRs![SID] <> 3 AND MyRs![SID] <> 5 AND MyRs![SID] <> 6) Then

    otherwise the logic allows it to fail.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    First off, the Time() Function returns a Date value, not a String. So

    Dim szTime As String

    needs to be

    Dim szTime As Date

    When denoting explicit DateTime values, you have to use the Octothorp (aka pound sign) as a delimiter.

    Next, to test if the time is between Midnight and 5 PM (I assume this is what you're trying to do) you have to use And rather than Or. So for this part of your code

    Code:
    Dim szTime As Date
    
    szTime = Time
    
     If TimeValue(szTime) > #12:00:00 AM# And TimeValue(szTime) < #5:00:00 PM# Then
    
      'Code if time is between 12 MN and 5 pm
    
     Else
    
      'Code if time is Not between 12 MN and 5 pm
    
     End If
    Lastly, is this all of your code or have you omitted some of it? With

    MyRs![SID]

    you appear to be referring to a RecordSet (MyRs) but you don't show where you're setting MyRs as such.

    Linq ;0)>

  4. #4
    Elin is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Sep 2014
    Posts
    3

    Better logic now :) but it is something more to it as well..

    Thank you! I also see why I should change also "00:00:00" Or TimeValue(.. to 00:00:00" And TimeValue !
    Howevers it's something more to it as I still get Datumtid=StartDatum


    Quote Originally Posted by ranman256 View Post
    I think
    (MyRs![SID] <> 3 Or MyRs![SID] <> 5 Or MyRs![SID] <> 6) Then

    needs to be AND...
    (MyRs![SID] <> 3 AND MyRs![SID] <> 5 AND MyRs![SID] <> 6) Then

    otherwise the logic allows it to fail.

  5. #5
    Elin is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Sep 2014
    Posts
    3
    Thank you!
    Yes I omitted quite a lot of code

    I'm going to change szTime toAs Date and put it to the test tonight!
    (And I realized the And bit in testing time! )

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

Similar Threads

  1. Yesterday's Date ignoring weekends
    By coletteabrown in forum Access
    Replies: 4
    Last Post: 12-09-2013, 08:02 AM
  2. Write code to see all date between two date
    By barkarlo in forum Programming
    Replies: 2
    Last Post: 02-24-2013, 10:58 AM
  3. Replies: 6
    Last Post: 10-05-2012, 02:38 PM
  4. How To Parse and Re Write A Date Field
    By abrogard in forum Access
    Replies: 2
    Last Post: 07-08-2012, 07:19 PM
  5. Replies: 5
    Last Post: 05-24-2012, 02:34 PM

Tags for this Thread

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