Public Function DaysInMonth(ADate As Date) As Integer
' this function will determine number of days in a month Dim dteNextMonth As Date Dim dteCurMonth As Date ' set the day of the month passed in to the 1st day dteCurMonth = CDate(DateAdd("d", -Day(ADate), ADate) + 1) dteNextMonth = DateAdd("m", 1, dteCurMonth) ' determine the number of days DaysInMonth = DateDiff("d", dteCurMonth, dteNextMonth) End Function ' this is the subroutine that used the function. ' the prefix "udb" stands for up/down button which is a ' standard microsoft control. Private Sub udbDateChange_UpClick() ' this subroutine handles the user clicking on the up ' arrow to change dteStartDate and dteEndDate are module ' level variables. Dim intNumDays As Integer ' this will increment the start and end dates dteStartDate = DateAdd("m", 1, dteStartDate) ' this was defaulted at form load intNumDays = DaysInMonth(dteStartDate) dteEndDate = DateAdd("d", intNumDays - 1, dteStartDate) txtStartDate.Text = Format(dteStartDate, "mm/dd/yyyy") txtEndDate.Text = Format(dteEndDate, "mm/dd/yyyy") End Sub Inputs: a starting date either input from user or defaulted to current date. |