I am new with VBA programming. I have designed one form in which there is a button. After clicking this button I want to insert record in my table having one date column. Th
Please, see below code and read comments:
Option Explicit
Sub Command0_Click()
Dim startDate As Date
Dim endDate As Date
Dim curDate As Date
'get first day from current date
startDate = GetFirstDayInMonth(Date)
'get last day from startDate
endDate = GetLastDayInMonth(startDate)
'loop through the dates
For curDate = startDate To endDate
'here call the procedure to insert data
Next
End Sub
'function to return first date in the month
Function GetFirstDayInMonth(dCurDate As Date) As Date
GetFirstDayInMonth = DateSerial(Year(dCurDate), Month(dCurDate), 1)
End Function
'return last date in the month
Function GetLastDayInMonth(dCurDate As Date) As Date
GetLastDayInMonth = DateSerial(Year(dCurDate), Month(dCurDate) + 1, 1 - 1)
End Function