>i need to
It'd be helpful if you set out your requirements at the outset.
Anyway, this is trivial. There are several approaches you could take. Here are two. Note in the first that there is almost no change to the FillFlexGrid routine
Code: Select all
Option Explicit
Public ANNO As Long
Public Sub FillFlexgrid()
Dim M As Long
Dim D As Long
MSFlexGrid1.Redraw = False ' speed up filling the grid by delaying redraw until all cells populated
For M = 1 To 12
MSFlexGrid1.ColWidth(M - 1) = 1100 ' set col width if you need to
For D = Day(DateSerial(ANNO, M, 1)) To Day(DateSerial(ANNO, M + 1, 0))
MSFlexGrid1.Col = M - 1
MSFlexGrid1.Row = D '- 1
MSFlexGrid1.Text = Format(DateSerial(ANNO, M, D), "short date")
Next
'End If
Next
MSFlexGrid1.Redraw = True
End Sub
Public Sub ResetGrid()
' Set up our flexgrid rows and columns
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Rows = 32
MSFlexGrid1.Cols = 12
MSFlexGrid1.FormatString = "^JAN|^FEB|^MAR|^APR|^MAY|^JUN|^JUL|^AUG|^SEP|^OCT|^NOV|^DEC" ' read the documentation to understand this
FillFlexgrid
End Sub
Private Sub Combo1_Click()
ANNO = Combo1 ' Pick up Anno from combobox
ResetGrid ' redo the grid with newly selected Anno
End Sub
Private Sub Form_Initialize()
'Load combo with a few years for sake of example - obviously in your code you populate this however you like
Combo1.AddItem "2020"
Combo1.AddItem "2021"
Combo1.AddItem "2022"
Combo1.AddItem "2023"
End Sub
Here's the second. Note the additional code in FillFlexGrid which is doing all the work that was done by the FormatString method in the ResetGrid routine of the first example
Code: Select all
Option Explicit
Public ANNO As Long '= 2021
' Assumes we have a 12C x 31R flexgrid with no fixed row or column
Public Sub FillFlexgrid()
Dim M As Long
Dim D As Long
MSFlexGrid1.Redraw = False ' speed up filling the grid by delaying redraw until all cells populated
For M = 1 To 12
MSFlexGrid1.Row = 0
MSFlexGrid1.Col = M - 1
MSFlexGrid1.Text = Format(DateSerial(ANNO, M, 1), "mmm")
MSFlexGrid1.ColWidth(M - 1) = 1100 ' set col width if you need to
MSFlexGrid1.ColAlignment(M - 1) = flexAlignCenterCenter
If M > 0 Then
For D = Day(DateSerial(ANNO, M, 1)) To Day(DateSerial(ANNO, M + 1, 0))
MSFlexGrid1.Col = M - 1
MSFlexGrid1.Row = D '- 1
MSFlexGrid1.Text = Format(DateSerial(ANNO, M, D), "short date")
Next
End If
Next
MSFlexGrid1.Redraw = True
End Sub
Public Sub ResetGrid()
' Set up our flexgrid rows and columns
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Rows = 32
MSFlexGrid1.Cols = 12
FillFlexgrid
End Sub
Private Sub Combo1_Click()
ANNO = Combo1 ' Pick up Anno from combobox
ResetGrid ' redo the grid with newly selected Anno
End Sub
Private Sub Form_Initialize()
'Load combo with a few years for sake of example - obviously in your code you populate this however you like
Combo1.AddItem "2020"
Combo1.AddItem "2021"
Combo1.AddItem "2022"
Combo1.AddItem "2023"
End Sub