Ok here is the full code. I have this in the click event of the calendar control.
Code:
MSFlexGrid1.Clear
MSFlexGrid1.TextMatrix(0, 0) = "TIME"
strResource = "Select * from ResSched where " & _
"[Date] = #" & Calendar1.Value & "#"
Dim theTime As Variant
theTime = TimeValue("8:00")
Dim incrementVal As Integer
Dim index As Integer
If cmbInterval.Text = "10" Then
incrementVal = 10
For index = 1 To 55
MSFlexGrid1.Rows = index + 1
MSFlexGrid1.TextMatrix(index, 0) = theTime
'Increment theTime
theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
Next
ElseIf cmbInterval.Text = "15" Then
incrementVal = 15
For index = 1 To 37
MSFlexGrid1.Rows = index + 1
MSFlexGrid1.TextMatrix(index, 0) = theTime
'Increment theTime
theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
Next
ElseIf cmbInterval.Text = "20" Then
incrementVal = 20
For index = 1 To 28
MSFlexGrid1.Rows = index + 1
MSFlexGrid1.TextMatrix(index, 0) = theTime
'Increment theTime
theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
Next
ElseIf cmbInterval.Text = "30" Then
incrementVal = 30
For index = 1 To 20
MSFlexGrid1.Rows = index + 1
MSFlexGrid1.TextMatrix(index, 0) = theTime
'Increment theTime
theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
Next
ElseIf cmbInterval.Text = "60" Then
incrementVal = 60
For index = 1 To 10
MSFlexGrid1.Rows = index + 1
MSFlexGrid1.TextMatrix(index, 0) = theTime
'Increment theTime
theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
Next
End If
Set rsHeader = New Recordset
With rsHeader
.Open strResource, madocon, adOpenDynamic, adLockOptimistic, adCmdText
count1 = 1
Do While count1 <> MSFlexGrid1.Cols
MSFlexGrid1.ColWidth(count1) = 2000
count1 = count1 + 1
Loop
count1 = 1
Do While .EOF = False
If count1 > 10 Then
MSFlexGrid1.Cols = count1 + 1
End If
MSFlexGrid1.TextMatrix(0, count1) = !RName
count1 = count1 + 1
rsHeader.MoveNext
Loop
End With
rsHeader.Close
Set rsHeader = Nothing
strPopulate = "Select * From Appointment Where" & _
"[AppDate] = #" & Calendar1.Value & "#"
Set rsPopulate = New Recordset
With rsPopulate
.Open strPopulate, madocon, adOpenDynamic, adLockOptimistic, adCmdText
If .EOF = True Then
Exit Sub
Else
rsPopulate.MoveFirst
Do While .EOF = False
MSFlexGrid1.TextMatrix(!TID, !AIdNum) = !AFName
rsPopulate.MoveNext
Loop
End If
End With
rsPopulate.Close
Set rsPopulate = Nothing
The problem is the calendar controls value does not change unless you click a day.
One more problem when I change the month and do not click a day and then go back to the previous month the flexgrid is cleared. It doesn't reload until I click a day.
Not sure how you should handle that. The date is always the same, unless user clicks on the calendar. If this is that much of an issue, why not use the DTPicker control? It has a mini-dropdown calendar of it's own...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
If you interested furthur you could add more code into your newmonth and newyear events to select the date based off that month (you'd have to check if the new month had the same number of days as the old month for this to be effective)...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....