Hello,
I've used the calendar from the post:
I've used the widescreen calendar from Post #327.
Now i want to populate the calendar with 2 dates from the same table in stead of 1.
It now populates the field "Date" (with some additional client-fields like adres, postal, etc).
The second date that should be populated is "Datum_Werkzamh eden" with the same additional client-fields.
The currnt VBA code that populates the calendar is:
I've used the calendar from the post:
I've used the widescreen calendar from Post #327.
Now i want to populate the calendar with 2 dates from the same table in stead of 1.
It now populates the field "Date" (with some additional client-fields like adres, postal, etc).
The second date that should be populated is "Datum_Werkzamh eden" with the same additional client-fields.
The currnt VBA code that populates the calendar is:
Code:
Private Sub PopulateCalendar()
On Error GoTo Err_PopulateCalendar
Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As TextBox
Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
Dim astrCalendarBlocks(1 To 42) As String, db As DAO.Database, rstEvents As DAO.Recordset
Dim strEvent As String
Dim lngSystemDate As Long 'CFB added 1-25-08
Dim ctlSystemDateBlock As TextBox, blnSystemDateIsShown As Boolean 'CFB added 1-25-08
Dim strSQL As String 'Added 4/16/2008
Dim lngFirstDateInRange As Long 'CFB added 2-18-10
Dim lngLastDateInRange As Long '
Dim lngEachDateInRange As Long '
Dim strStartTime As String '
lngSystemDate = Date 'CFB added 1-25-08
intMonth = objCurrentDate.Month
intYear = objCurrentDate.Year
lstEvents.Visible = True
lblEventsOnDate.Visible = False
lstEvents2.Visible = True
lblMonth.Caption = MonthAndYear(intMonth, intYear)
'strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
strFirstOfMonth = Str(intMonth) & "/1/" & Str(intYear)
'*************************************************************************
'ADezii
'NOTE: Will work in the UK (United Kingdom) and other European Nations
'strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
'*************************************************************************
bytFirstWeekdayOfMonth = WeekDay(strFirstOfMonth)
lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
lngLastOfMonth = lngFirstOfNextMonth - 1
lngLastOfPreviousMonth = lngFirstOfMonth - 1
bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
Set db = CurrentDb
strSQL = "SELECT sales1.naam_klant, sales1.woonplaats, sales1.date, tblVisitType.Type, " & _
"tblVisitType.Code, sales1.time " & _
"FROM tblVisitType INNER JOIN sales1 ON tblVisitType.TypeID = sales1.TypeID " & _
"WHERE sales1.date Between #" & CDate(lngFirstOfMonth) & "# And #" & CDate(lngLastOfMonth) & "# " & _
"ORDER BY sales1.time, sales1.naam_klant, sales1.woonplaats;"
Set rstEvents = db.OpenRecordset(strSQL) 'Added 4/16/2008
'MsgBox IsDate(rstEvents![Date])
'With rstEvents
' If .BOF And .EOF Then 'NO Records
' MsgBox "rstEvents contains 0 Records"
' Else
' .MoveLast: .MoveFirst 'for accurate Record Count
' MsgBox "rstEvents consists of " & .RecordCount & " Records"
' MsgBox "[Date] " & IIf(IsDate(![Date]), " IS ", " IS NOT ") & _
' "recognized by Access as a Valid Date Field"
' End If
' .Close: Set rstEvents = Nothing
' End With
' Exit Sub
Do While Not rstEvents.EOF
'CFB added 2-18-10
'lngFirstDateInRange = CDate(rstEvents![Date])
lngFirstDateInRange = rstEvents![Date] '<Substitute for [Start Date]>
If lngFirstDateInRange < lngFirstOfMonth Then
lngFirstDateInRange = lngFirstOfMonth
End If
'lngLastDateInRange = CDate(rstEvents![Date])
lngLastDateInRange = rstEvents![Date] '<Substitute for [End Date]>
If lngLastDateInRange > lngLastOfMonth Then
lngLastDateInRange = lngLastOfMonth
End If
For lngEachDateInRange = lngFirstDateInRange To lngLastDateInRange
bytEventDayOfMonth = (lngEachDateInRange - lngLastOfPreviousMonth)
bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
'<Substitute for [Title]>
If astrCalendarBlocks(bytBlockCounter) = "" Then
' astrCalendarBlocks(bytBlockCounter) = Format$(rstEvents![Time], "hh:nn AM/PM") & vbCrLf & rstEvents![naam_klant] & ", " &
astrCalendarBlocks(bytBlockCounter) = Format$(rstEvents![Time], "hh:nn") & vbCrLf & rstEvents![Naam_Klant] & ", " & _
Left$(rstEvents![Woonplaats], 1) & "." & " [" & rstEvents! & "]"
Else '<Substitute for [Title]>
astrCalendarBlocks(bytBlockCounter) = astrCalendarBlocks(bytBlockCounter) & vbNewLine & _
Format$(rstEvents![Time], "hh:nn") & vbCrLf & rstEvents![Naam_Klant] & ", " & _
Left$(rstEvents![Woonplaats], 1) & "." & " [" & rstEvents! & "]"
' Format$(rstEvents![Time], "hh:nn AM/PM") & vbCrLf & rstEvents![naam_klant] & ", " &
End If
Next lngEachDateInRange
'End of CFB added 2-18-10
rstEvents.MoveNext
Loop
For bytBlockCounter = 1 To 42 'blank blocks at start of month
Select Case bytBlockCounter
Case Is < bytFirstWeekdayOfMonth
astrCalendarBlocks(bytBlockCounter) = ""
ReferenceABlock ctlDayBlock, bytBlockCounter
'ctlDayBlock.BackColor = 12632256
ctlDayBlock.BackColor = 8421440
ctlDayBlock = ""
ctlDayBlock.Enabled = False
ctlDayBlock.Tag = ""
Case Is > bytBlankBlocksBefore + bytDaysInMonth 'blank blocks at end of month
astrCalendarBlocks(bytBlockCounter) = ""
ReferenceABlock ctlDayBlock, bytBlockCounter
'ctlDayBlock.BackColor = 12632256
ctlDayBlock.BackColor = 8421440
ctlDayBlock = ""
ctlDayBlock.Enabled = False
ctlDayBlock.Tag = ""
ctlDayBlock.Visible = Not (bytBlankBlocksAfter > 6 And bytBlockCounter > 35)
Case Else 'blocks that hold days of the month
bytBlockDayOfMonth = bytBlockCounter - bytBlankBlocksBefore
ReferenceABlock ctlDayBlock, bytBlockCounter
lngBlockDate = lngLastOfPreviousMonth + bytBlockDayOfMonth 'block's date
If bytBlockDayOfMonth < 10 Then
ctlDayBlock = Space(2) & bytBlockDayOfMonth & _
vbNewLine & astrCalendarBlocks(bytBlockCounter)
Else
ctlDayBlock = bytBlockDayOfMonth & _
vbNewLine & astrCalendarBlocks(bytBlockCounter)
End If
'If this block is the system date, change its color (CFB 1-25-08)
If lngBlockDate = lngSystemDate Then
ctlDayBlock.BackColor = RGB(0, 0, 255)
ctlDayBlock.ForeColor = QBColor(15)
Set ctlSystemDateBlock = ctlDayBlock
blnSystemDateIsShown = True
Else
ctlDayBlock.BackColor = QBColor(15)
ctlDayBlock.ForeColor = 8388608 '====> Added by ADezii on 1/28/2008 (Date
End If 'Text was essentially invisible without it for
ctlDayBlock.Visible = True 'Block representing current day position)
ctlDayBlock.Enabled = True
ctlDayBlock.Tag = lngBlockDate
End Select
Next
'If the system date is in this month, show its events (CFB added 1-25-08)
If blnSystemDateIsShown Then
PopulateEventsList ctlSystemDateBlock
PopulateEventsList2 ctlSystemDateBlock
End If
Call PopulateYearListBox 'Added by ADezii on 1/28/2008 - suggested by CFB
Exit_PopulateCalendar:
Exit Sub
Err_PopulateCalendar:
MsgBox Err.Description, vbExclamation, "Error in PopulateCalendar()"
Call LogErrors(Err.Number, Err.Description, "frmCalendar", "PopulateCalendar() Sub-Routine", "Called from Multiple Locations")
Resume Exit_PopulateCalendar
End Sub
Comment