My form has two text boxes, txtDateFrom and txtDateTo. A macro button with the caption Month is to automatically fill in txtDateFrom and txtDateTo with current month date. My code reads as:
But it's giving me wrong date: 1/5/09 and 2/4/09. I expect it to show 5/1/09 and 5/31/09
By the way, macros for Today, Week and Year are working just fine. These codes are as follow:
TODAY
THIS WEEK
I need your experties to help me with my code for MONTH. Thanks.
Code:
Private Sub cmdmonth_Click()
'Sets the Date From and Date To text boxes
'to show complete month (from start to end of current month)
Me!txtdatefrom = CDate("01/" & Month(Date) & "/" & Year(Date))
Me!txtDateTo = DateAdd("d", -1, DateAdd("m", 1, Me!txtdatefrom))
End Sub
By the way, macros for Today, Week and Year are working just fine. These codes are as follow:
TODAY
Code:
Private Sub cmdtoday_Click()
'Sets the Date From and Date To text boxes
'to Today's Date
Me!txtdatefrom = Date
Me!txtDateTo = Date
End Sub
Code:
Private Sub cmdweek_Click()
'Sets the Date From and Date To text boxes
'to show complete working week (Mon - Fri)
Dim today
today = Weekday(Date)
Me!txtdatefrom = DateAdd("d", (today * -1) + 2, Date)
Me!txtDateTo = DateAdd("d", 6 - today, Date)
End Sub
Comment