Results 1 to 4 of 4
  1. #1
    Coasterman is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2019
    Posts
    8

    Test for 'x' number of hours before a time on todays date

    Im doing some form validation on some short time fields.



    I need to test to see if the users input into Time_Start ouside the period 06:00AM to 06:00PM

    The date part of the validation has to be handled separately in another field as users wont necessarily be recording the event on the day it occurs but the Start_Times and End_Time period won't vary.

    The below is giving me msgbox warnings regardles of the times I enter?

    Code:
    If Me.Time_Start < ("06:30AM") Then    
       MsgBox "msgbox warning etc....."
    End If
    
    
    If Me.Time_Start > ("06:00PM") Then
       MsgBox "some other warning....."
    End If
    I thought perhaps it was the fact I hadn't specified that the date was today but for me that doesn;t ring true as if the user is only entering a time how would Access possibly know that time related to any specific date?

    I have read quite a bit on dates/Times over the past few days but this is still confusing to me.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The below is giving me msgbox warnings
    Which are??
    " are string delimiters. # are date/time delimiters. Unless you are actually comparing a string as "06:30AM" (which you are not)
    then it is #06:30AM#
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    and time_start needs to be just the time and not include a date element

  4. #4
    Join Date
    Apr 2017
    Posts
    1,673
    Less prone to possible errors caused by different regional settings will be
    Code:
    If Me.Time_Start < TimeSerial(6,30,0) Then    
       MsgBox "msgbox warning etc....."
    End If
    
    
    If Me.Time_Start > TimeSerial(18,30,0) Then
       MsgBox "some other warning....."
    End If

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

Similar Threads

  1. Replies: 8
    Last Post: 02-08-2017, 07:58 PM
  2. Replies: 3
    Last Post: 06-13-2014, 09:16 PM
  3. Replies: 5
    Last Post: 05-14-2014, 03:19 PM
  4. Replies: 4
    Last Post: 08-06-2012, 10:25 AM
  5. Replies: 3
    Last Post: 07-09-2012, 05:59 AM

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