Monthview Control - Using Left & Right Arrows to Choose Month
My project uses a monthview control to allow the user to select a date for their data entry. I also have a function that bolds the dates on the monthview control so that the users can see where they've entered data already.
The function itself works perfectly (I'll post it's code at the bottom of my post), but I there's one tiny issue. If the user clicks the left and right arrows at the top of the monthview control to navigate through different months, it works. If they click through the months too fast though, it doesn't work.
For example, let's say I have data entered for January 2 and February 2, 2010. If my calendar control is set to December 2009 and I slowly click the right arrow it will show Jan 2, 2010 in bold and then Feb 2, 2010 in bold. However, if my monthview is in December and I click twice quickly, it shoots me through to Feb, 2010 but the 2nd is not bolded.
I assumed I needed to call the function below from the "double-click" event on my monthview control but of all the events I've tried, none seem to correct the problem. Any ideas?
Code:
Public Function PopulateDateBoldArray(ByVal strCRNumber As String, strReviewDate As Date)
'This function highlights the dates on the main form calendar where review data is present
Dim rsDateList As ADODB.RecordSet
Set rsDateList = New ADODB.RecordSet
Dim strDate As String
Dim strSQL As String
Dim intCount As Integer
intCount = 0
'Erase DatesToBold()
'CalendarMonth = frmMain.monReviewDates.Month
strDate = Format(strReviewDate, "MM/DD/YYYY")
strSQL = "SELECT Location.Location_Date " & _
"FROM Master_Review INNER JOIN Location ON Master_Review.ID = Location.ID " & _
"Where Master_Review.CR_Number = '" & strCRNumber & "' And Master_Review.Review_Date = " & "#" & strDate & "#" & _
"ORDER BY Location.Location_Date"
With rsDateList
.Open strSQL, conAccess, adOpenStatic, adLockOptimistic
' ReDim DatesToBold(.RecordCount) As Date
Do While Not .EOF
If DatePart("m", frmMain.monReviewDates) = DatePart("m", .Fields!Location_Date) Then
frmMain.monReviewDates.DayBold(.Fields!Location_Date) = True
End If
.MoveNext
intCount = intCount + 1
Loop
End With
Set rsDateList = Nothing
End Function
Re: Monthview Control - Using Left & Right Arrows to Choose Month
Grudge
Would it help if you added a DoEvents statement in the
"click" event of your monthview control?
Spoo
Re: Monthview Control - Using Left & Right Arrows to Choose Month
Have you tried responding to the GetDayBold event?
Code:
Private Sub MonthView1_GetDayBold(ByVal StartDate As Date, ByVal Count As Integer, State() As Boolean)
' StartDate is the 1st date displayed on the month view, not necessarily 1st day of the month
' Count is the number of days displayed on the month view currently
' -- can be partially previous month
' -- should be entire current month
' -- can be partially next month
' State() is a boolean array
' -- State(0) = StartDate's bold value
' -- State(Count-1) = Bold value of last date on view
' Now, because I think you are concerned with the current month being displayed (single month view),
' It would be nice to quickly know which State() item is Day 1 of month and which
' State() is the last day of the month. So...
Dim Offset As Long, nrDays As Long
Offset = DateDiff("d", StartDate, DateSerial(MonthView1.Year, MonthView1.Month, 1))
nrDays = Day(DateSerial(MonthView1.Year, MonthView1.Month + 1, 0))
' for testing purposes, set the 1st & last days of month as bold
State(Offset) = True: State(Offset + nrDays - 1) = True
End Sub
Edited: Maybe a better solution vs starting with day 1 and ending in last day of month is to query your database in the range of StartDate to DateAdd("d", Count-1, StartDate) and fill in the State() array from 0 to Count-1. That way the bolded days in any partial months shown on the monthview will be bolded too.