Public Function Display(grd As MSFlexGrid)
If Rs.State = 1 Then Rs.Close
SQL = "SELECT * FROM Tbl_Cal"
Rs.Open SQL, Con
Rs.MoveFirst
While Not Rs.EOF
Dim theDate As Long
Dim m_Date As Long
Dim lastDate As Long
Dim firstDate As Long
Dim firstCol As Long
Dim wRows As Long
Dim wRow As Long
Dim wCol As Long
Dim wDate As Long
Dim rDate As Long
[COLOR=#008000]' Date = NOW[/COLOR]
m_Date = Date
theDate = m_Date
[COLOR=#008000]' DECLARE FIRST DATE OF THE MONTH[/COLOR]
firstDate = DateSerial(Year(theDate), Month(theDate), 1)
[COLOR=#008000]' DECLARE LAST DATE OF THE MONTH[/COLOR]
lastDate = DateSerial(Year(theDate), Month(theDate) + 1, 1) - 1
[COLOR=#008000] ' DECLARE THE FIRST COLUMN OF GRID[/COLOR]
firstCol = Weekday(firstDate, vbUseSystemDayOfWeek) - 1
[COLOR=#008000] ' DECLARE THE NUMBER OF ROWS[/COLOR]
wRows = DateDiff("ww", firstDate, lastDate, vbUseSystemDayOfWeek) + 1
Form1.lblDate.Caption = Format(Date, "mmmm - yyyy")
With grd
.Appearance = flexFlat
.ScrollBars = flexScrollBarNone
[COLOR=#008000]' Just some color settings[/COLOR]
.GridColor = vbWhite
.BackColor = .GridColor
[COLOR=#008000]' No highlighting[/COLOR]
.HighLight = flexHighlightNever
.FocusRect = flexFocusLight
' Enable texts to span multiple lines
.WordWrap = True
[COLOR=#008000]' Number of days in a week [/COLOR]
.Cols = 7
[COLOR=#008000]' For the date header[/COLOR]
.Rows = wRows * 5
.Clear
wRow = 0
wCol = firstCol - 1
For wDate = firstDate To lastDate
wCol = wCol + 1
If wCol > 6 Then
wRow = wRow + 2
wCol = 0
End If
.Col = wCol
.Row = wRow
[COLOR=#008000]' header design
' Display number of days[/COLOR]
.TextMatrix(wRow, wCol) = Format(wDate, "d")
[COLOR=#008000]' Alingment of number of days[/COLOR]
.CellAlignment = flexAlignLeftCenter
If Weekday(wDate, vbMonday) > 5 Then
.CellBackColor = &HFFC0C0 [COLOR=#008000]' weekend header cell color[/COLOR]
Else
.CellBackColor = &HFFFFC0[COLOR=#008000] ' weekdays header cell color[/COLOR]
End If
[COLOR=#008000]' Current date Header Color[/COLOR]
If wDate = Date Then .CellBackColor = &H8000000D
.Row = wRow + 1 ' adjust to the Cell below the header
[COLOR=#008000]' Cell below the header design[/COLOR]
.CellAlignment = flexAlignCenterCenter
.CellFontBold = True
If Weekday(wDate, vbMonday) > 5 Then
[COLOR=#008000]' weekend cell color[/COLOR]
.CellBackColor = vbWhite
Else
[COLOR=#008000]' weekday cell color[/COLOR]
.CellBackColor = vbWhite
[COLOR=#008000]' this is where you can retrieve data from db and display it to grid[/COLOR]
If wDate = DateValue(Rs.Fields(1).Value) Then .Text = Rs.Fields(2).Value
End If
[COLOR=#008000]' Current date cell color[/COLOR]
If wDate = Date Then .CellBackColor = &H8000000F
Next wDate
.FixedRows = 0
.FixedCols = 0
.Col = firstCol
.Row = 1
End With
Rs.MoveNext
Wend
End Function