RE: Date Minues Month

Tech-Archive recommends: Fix windows errors by optimizing your registry



That function won't quite work as posted. It would need to be;

========================================
Function Thorsons_Date(dte As Date) As Date
Dim dteTemp As Date

dteTemp = DateAdd("m", -1, dte)

Do Until Month(dteTemp) <> Month(DateAdd("d", 1, dteTemp))
dteTemp = DateAdd("d", 1, dteTemp)
Loop

Thorsons_Date = dteTemp

End Function
==========================================


However, it would be easier just to use the DateSerial function;

DateSerial(Year(Date()), Month(Date()), 0)

will return the last day of the previous month. No additional code needed.
--
_________

Sean Bailey


"Rob Wills" wrote:

write a function that you then reference from your query....

====================================
Function Thorsons_Date(dte as date) as date
dim dteTemp as date

dteTemp = Dateadd("M",-1,dte)

do until month(dteTemp) <> month(dateadd("D",1,dteTemp)
dateadd("D",1,dteTemp)
loop

Thorsons_Date = dteTemp

end function
=====================================

HTH
Rob


"Thorson" wrote:

Yes. The last date of the month prior to the one entered into the form.
--
Thorson


"Rob Wills" wrote:

Are you always looking for the last day of the month?

"Thorson" wrote:

I've tried out several things and noticed a problem with the equation. If
the user types 11/30/2008 into the form it sets the parameter as 10/30/2008,
the problem is that there are 31 days in October, therefore I want it to set
the parameter as 10/31/2008. This is obviously going to change every month.

This is what I set the Critera to in the query:
<=DateAdd("m",-1,([Forms]![frmCurrentInventoryDateQuery]![txtDate]))

--
Thorson


"Rob Wills" wrote:

Hi,

Have you tried the Dateadd function?

Dateadd("M",-1,"20 Dec 08")

HTH
Rob

"Thorson" wrote:

I currently have a query that sets the criteria of the records by a date
entered into a control on a form. I would like to create another query that
has the criteria set to the date to the date on the control form Minus 1
month (which could be 28, 29, 30 or 31 days) How do I do that?
--
Thorson
.



Relevant Pages

  • RE: Date Minues Month
    ... Dim dteTemp As Date ... "Rob Wills" wrote: ... "Thorson" wrote: ... has the criteria set to the date to the date on the control form Minus 1 ...
    (microsoft.public.access.queries)
  • Re: Access Date Hell
    ... Dim dteTemp As Date ... Dim lngDays As Long ... ' Remove any time portion of the date ...
    (comp.databases.ms-access)
  • Days in month
    ... Not a built in, but the UDF is pretty simple: ... Dim dteTemp As Date ...
    (microsoft.public.access.gettingstarted)