/ Published in: Visual Basic
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
Sub BuildCalendarPeriodTable(BeginDate As Date, EndDate As Date)
Dim rs As DAO.Recordset
Dim dt As Date
Dim mo As Byte
Dim qt As Byte
Dim yr As Integer
Dim firstDay As Date
Dim lastDay As Date
Set rs = CurrentDb.OpenRecordset("Period")
For dt = BeginDate To EndDate
' Only update table on first day of month
If Day(dt) = 1 Then
' Get the month and year
mo = Month(dt)
yr = Year(dt)
' Get first and last days of month
firstDay = dt
lastDay = LastDayOfMonth(mo, yr)
Select Case mo
Case 1 To 3
qt = 1
Case 4 To 6
qt = 2
Case 7 To 9
qt = 3
Case 10 To 12
qt = 4
End Select
' Add the row
With rs
.AddNew
!PeriodId = yr & Format(mo, "00")
!CalMthNm = Format(dt, "mmmm")
!CalMthNbr = mo
!QtrNbr = qt
!YearNbr = yr
!PeriodBeginDt = firstDay
!PeriodEndDt = lastDay
.Update
End With
End If
Next dt
Set rs = Nothing
End Sub
Comments
 Subscribe to comments
                    Subscribe to comments
                
                