Results 1 to 6 of 6
  1. #1
    Amras is offline Novice
    Windows 2K Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Sioux Falls, SD
    Posts
    29

    Use Time value in SQL VBA as criteria

    Good afternoon, all. I'm trying to create an SQL query in VBA that will return a rep's schedule preferences by assembling the SELECT, FROM and WHERE portions of the query based on the report user's input on a form. The report user will check any of seven check-boxes to indicate the requested day/days of the week, then two text boxes into which they'll enter a start time and an end time. The data is stored in the table as Medium Time, however when the assembled SQL is tested, there are no results as the data in the table has no date component so its defaulting to 1/1/1900 as it's search criteria. With DatePart you can query for Hour or Minute, but not both (perhaps the rep has requested a schedule that starts at 8:30 am rather than 8:00 am or 9:00 am). This is the code that I have so far (I've only included the final checkbox as all of the other checkboxes mirror it):



    Code:
        If chkSaturday Then
            strSQLSaturday = "tblSchedulePreference.RequestSaturdayStart, tblSchedulePreference.RequestSaturdayEnd, "
            strWhereSaturday = "((tblSchedulePreference.RequestSaturdayStart)= # " & [Forms]![frmSchedulePreferenceReports]![txtBeginTime] & " #) AND ((tblSchedulePreference.RequestSaturdayEnd)=#" & [Forms]![frmSchedulePreferenceReports]![txtEndTime] & " #) AND "
        Else
            strSQLSaturday = ""
            strWhereSaturday = ""
        End If
        
        strSQLSelect = "SELECT tblSchedulePreference.LanID, tblEmployees.FullName, " & strSQLSunday & strSQLMonday & strSQLTuesday & strSQLWednesday & strSQLThursday & strSQLFriday & strSQLSaturday
        strSQLSelect = Left(strSQLSelect, Len(strSQLSelect) - 2)
        strSQLSelect = strSQLSelect & " "
    
        strSQLFrom = "FROM tblSchedulePreference INNER JOIN tblEmployees ON tblSchedulePreference.LanID = tblEmployees.LanID "
    
        strSQLWhere = strWhereSunday & strWhereMonday & strWhereTuesday & strWhereWednesday & strWhereThursday & strWhereFriday & strWhereSaturday
        strSQLWhere = Left(strSQLWhere, Len(strSQLWhere) - 5)
        strSQLWhere = "Where (" & strSQLWhere & ");"
    
        strSQL = strSQLSelect & strSQLFrom & strSQLWhere
    I apologize if I'm making a obvious mistake. Any help you can provide will be appreciated!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    In Access, Date/Time is stored as a number. I believe it fits into a Double. Formatting does not have anything to do with how the number is stored. Formatting will determine how the number is displayed to humans.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Thinking you could concatenate DatePart values, or you could use the TimeSerial function.
    Just guessing since I can't tell what your doing with the time part when you query.
    FYI: the integer portion of the double precision date number is the date; the decimal portion is the time.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    and to follow on from Microns explanation, the date is expressed as the number of days from 'day zero' - today 2nd September is 42615, yesterday was 42614.

    And time is expressed as a fraction calculated as the number of seconds in the day to 'time' divided by the number of seconds in the day - e.g. time is now is 09:08:25 - number of seconds =(9hrs*60*60)+(8*60)+25=32905. number seconds in the day 24*60*60=86400 so expressed as 32905/86400=0.380844907407407

    So now() will return a value of 42615.380844907407407

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Ajax View Post
    ...
    So now() will return a value of 42615.380844907407407
    Apparently, you are living in the past. I get a later time.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I'm always trying to catch up

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

Similar Threads

  1. Replies: 2
    Last Post: 05-31-2016, 01:52 PM
  2. Replies: 6
    Last Post: 04-19-2016, 03:58 PM
  3. Unix time stamp date and criteria
    By madrag in forum Queries
    Replies: 5
    Last Post: 12-15-2014, 03:39 AM
  4. Replies: 2
    Last Post: 08-21-2014, 08:36 AM
  5. Date/Time Criteria
    By KWarzala in forum Queries
    Replies: 3
    Last Post: 06-04-2010, 07:08 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