Hi
I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread.
here is the original tread
Just to clarify what I am trying to achieve....
I have a table with calendar booking records which has been imported from outlook so the start date and end date are in this format dd:mm:yyyy hh:nn:ss this is what I believe is the root of the problem
I have a form that is designed to display the calendar bookings from the table in a monday - sunday format so a user selects a date and on the form the full week is displayed so for example if the user selects 9/9/09 the form will display from the 7/9/09 - 13/9/09 similar to how outlook works
The query that I was having problems with is designed to pick up the start and end date range on that form and return all the calendar bookings from the table within the date range I have now got this to work how I want it to
The problem I am now having is that the recordset is not picking up the correct records from the query but if you run the query by itself it displays the correct records
I suspect it has something to do with the following two lines of code
here is the code for the recordset
Any help is much appreciated
Regards Phill
I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread.
here is the original tread
Just to clarify what I am trying to achieve....
I have a table with calendar booking records which has been imported from outlook so the start date and end date are in this format dd:mm:yyyy hh:nn:ss this is what I believe is the root of the problem
I have a form that is designed to display the calendar bookings from the table in a monday - sunday format so a user selects a date and on the form the full week is displayed so for example if the user selects 9/9/09 the form will display from the 7/9/09 - 13/9/09 similar to how outlook works
The query that I was having problems with is designed to pick up the start and end date range on that form and return all the calendar bookings from the table within the date range I have now got this to work how I want it to
Code:
SELECT DateValue([TblCalendarS104].[StartDate]) AS Expr1,
DateValue([TblCalendarS104].[EndDate]) AS Expr2,
TblCalendarS104.StartDate,
TblCalendarS104.EndDate
FROM TblCalendarS104
WHERE CDate(((DateValue(TblCalendarS104.StartDate))>=Forms!FrmCalendarMain!SfrCalS104.Form!txtmon)
AND CDate((DateValue(TblCalendarS104.EndDate))<=Forms!FrmCalendarMain!SfrCalS104.Form!txtsun));
I suspect it has something to do with the following two lines of code
Code:
qdf.Parameters(0) = [Forms]![FrmCalendarMain]![SfrCalS104]![TxtMon] qdf.Parameters(1) = [Forms]![FrmCalendarMain]![SfrCalS104]![TxtSun]
Code:
Dim strControlName As String
Dim dbsEquipBook As DAO.Database
Dim rstCheck As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim BookedStartTime As Date
Dim BookedEndTime As Date
Dim MyDate, MyWeekDay As Date
Dim FirstDay As Date
Dim LastDay As Date
Dim MondayForm As Date
'works out the first and last day of the week according to the selected date from the calendar
MyDate = [Forms]![FrmCalendarMain].[frmCalendar]![txtDate]
MyWeekDay = Weekday(MyDate)
FirstDay = MyDate - MyWeekDay + 2
LastDay = MyDate - MyWeekDay + 8
'writes the first and last date to form
[Forms]![FrmCalendarMain].[frmCalendar].SetFocus
[Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon] = FirstDay
[Forms]![FrmCalendarMain].[SfrCalS104]![TxtSun] = LastDay
Set dbsEquipBook = CurrentDb()
Set qdf = dbsEquipBook.QueryDefs("QSelS104calcheck")
qdf.Parameters(0) = [Forms]![FrmCalendarMain]![SfrCalS104]![TxtMon]
qdf.Parameters(1) = [Forms]![FrmCalendarMain]![SfrCalS104]![TxtSun]
Set rstCheck = qdf.OpenRecordset(dbOpenDynaset, dbReadOnly)
' loops through recordset this is where it is picking up the wrong records
Do While Not rstCheck.EOF
BookedStartTime = Format(rstCheck!StartDate, "hh:nn")
BookedEndTime = Format(rstCheck!EndDate, "hh:nn")
BookedDay = Format(rstCheck!StartDate, "ddd")
'handles midnight values
If BookedEndTime = "00:00:00" Then
BookedEndTime = "23:59:59"
End If
'this section loops through and changes colour of controls if criteria is met this represents the calendar bookings
For i = 8 To 23
For j = 0 To 1
If i < 10 Then
strControlName = "txt" & BookedDay & "0" & i & ":"
Else
strControlName = "txt" & BookedDay & i & ":"
End If
If j = 0 Then
strControlName = strControlName & "00"
Else
strControlName = strControlName & "30"
End If
If Forms![FrmCalendarMain].[SfrCalS104].Form.Controls(strControlName) >= BookedStartTime And Forms![FrmCalendarMain].[SfrCalS104].Form.Controls(strControlName) < BookedEndTime Then
Forms![FrmCalendarMain].[SfrCalS104].Form.Controls(strControlName).BackColor = RGB(191, 191, 191)
Forms![FrmCalendarMain].[SfrCalS104].Form.Controls(strControlName).ForeColor = RGB(191, 191, 191)
Forms![FrmCalendarMain].[SfrCalS104].Form.Controls(strControlName).Enabled = False
End If
Next
Next
rstCheck.MoveNext
Loop
rstCheck.Close
End Sub
Regards Phill
Comment