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!