I am trying to use the DateAdd function to find the last day of any month. I am using code that I saw on Microsoft's VB page. This is the code:


Dim TEMP2 as date
Dim nLastDay as Integer
RptDateBeg = DatePart("m", date) & "/01/" & DatePart("yyyy", date) & " 12:00:00 AM"
TEMP2 = RptDateBeg
nLastDay = DatePart("d", DateAdd("M", 1, TEMP2 - DatePart("d", TEMP2)))




The problem is for months with 31 days that follow months with 30 days it tells me the last day is the 30th instead of the 31st. It works with 30 day months. For example, for October it is giving me 10/30/01 as the last day. Any suggestions?