Results 1 to 5 of 5
  1. #1
    napiedra is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    17

    Code Time comparison

    I have this application that I have been using for over 8 month or more now but the boss wants to make a change. In our parking lot, drivers come in from 7:00 AM to 5:00 PM while we are open. If someone comes in before 11:00 AM The rate is given with a case statement in increments of $2 every 20 Min but if the driver wants to stay all day up to 5:00 the Max is $12:00. After 11:00 AM it is the same thing except that the MAX is only $7:00. I am trying to accomplish that with the following case but not only is not working it is giving me error on line color in bold RED. Can someone explain how I can compare the value of TimeIn with the time 11:00 AM and use each case base on that?

    Private Sub FindTAG_AfterUpdate()

    If Me.FindTAG & vbNullString <> vbNullString Then
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone
    rs.FindFirst "[TAG]=" & Me.FindTAG
    If rs.NoMatch Then
    DoCmd.GoToRecord acActiveDataObject, , acNewRec
    Me!TAG = Me.FindTAG
    Me.TimeIn = Now()
    Me.HourlyRate = 6
    MsgBox "Ticket Added, Click 'OK' To Continue!"
    DoCmd.GoToRecord acDataForm, "CTPLLC", acNewRec
    Forms!CTPLLC!FindTAG.SetFocus
    Else
    Me.Bookmark = rs.Bookmark
    If IsNull(Me.TimeOut) Then
    Me.TimeOut = Now()
    Me.ElapsedTime = DateDiff("n", [TimeIn], [TimeOut])
    Y = TimeIn
    If Y > #Date()11:00:01 AM#Then
    Select Case [ElapsedTime]
    Case 1 To 21
    X = 2
    Case 22 To 41
    X = 4
    Case 42 To 61
    X = 6
    Case 62 To 10000
    X = 7
    End Select
    Else
    Select Case [ElapsedTime]
    Case 1 To 21
    X = 2
    Case 22 To 41
    X = 4
    Case 42 To 61
    X = 6
    Case 62 To 81
    X = 8
    Case 82 To 101
    X = 10
    Case 102 To 10000
    X = 12
    End Select
    End If
    Me.AmountOwed = X

    If Me.Dirty Then
    Me.Dirty = False
    End If

    Else
    MsgBox "NOTICE:This is a previously Used Ticket!"
    Forms!CTPLLC!Next.SetFocus
    End If


    End If
    rs.Close
    FindTAG = Null
    End If
    End Sub
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:

    If Y > CDate(Date() & " 11:00:01 AM") Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    napiedra is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    17
    Thanks for the prompt response... The line that you suggested is still giving me a syntax error:

    If Y > #Date() & " 11:00:01 AM" & # Then

    I wanted to compare the TimeIn that came from the table to 11:00 AM and if that time was before 11 then do something but if it is after 11:00 AM do something else... Thanks for you help...

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Too fast, I edited my post after you read it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    napiedra is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    17
    You guys are good! I tested every possible scenario with times on the app and this thing rocks now! Thanks so much... We got it working good.

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

Similar Threads

  1. Time comparison based on date - Late Report
    By gryphin81 in forum Reports
    Replies: 8
    Last Post: 04-25-2014, 11:35 AM
  2. Time Clock Code
    By MakaiKing0 in forum Database Design
    Replies: 8
    Last Post: 04-08-2013, 06:10 AM
  3. Date/Time code
    By JayX in forum Access
    Replies: 13
    Last Post: 12-15-2011, 03:31 PM
  4. Each time I click run different code
    By Dominaz in forum Access
    Replies: 3
    Last Post: 11-14-2011, 08:44 AM
  5. Time Comparison
    By Larry819 in forum Queries
    Replies: 1
    Last Post: 06-22-2009, 09:26 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