date format

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I asked this question yesterday and got a response but Im
still having problems and I didnt know how far back the
moderators look.

I have a field on a form asking for a date ([Date]) and Im
trying to find a way to make a hidden field ([Previous])
automatically contain the first date of the previous
month. For Example, if [Date]="8/1/03", then [Previous]
= "7/1/03", what is the calculation for that?

The solutions I received were:
Me.[Previous] = DateSerial(Year(CDate(Me.[CurrDate])),
Month(CDate(Me.[CurrDate])) - 1, 1)
and
DateSerial(Year([Date]), Month([Date]) - 1, 1)

I tried both and what I got was:
[Date]=8/1/03, then [Previous] = 7/27/03

I didnt actually use [Date] as the field name, just for
the example.
 
Rob said:
I asked this question yesterday and got a response but Im
still having problems and I didnt know how far back the
moderators look.

I have a field on a form asking for a date ([Date]) and Im
trying to find a way to make a hidden field ([Previous])
automatically contain the first date of the previous
month. For Example, if [Date]="8/1/03", then [Previous]
= "7/1/03", what is the calculation for that?

The solutions I received were:
Me.[Previous] = DateSerial(Year(CDate(Me.[CurrDate])),
Month(CDate(Me.[CurrDate])) - 1, 1)
and
DateSerial(Year([Date]), Month([Date]) - 1, 1)

I tried both and what I got was:
[Date]=8/1/03, then [Previous] = 7/27/03

I didnt actually use [Date] as the field name, just for
the example.

Something doesn't make sense here. The last argument for DateSerial is the day of
the month and you are hard-coding a one for that value. There is no way that this
can return 7/27/03. Even if the other parts of the expression were wrong you have to
get a date on the first of the month.

Break this into steps. First try...

Me.[Previous] = DateSerial(2003, 7, 1)

....just to prove that you get 7/1/2003 out of it. Then replace the first two
arguments one at a time and see what happens.


--
*******************************
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
*******************************
 
Thanks for all the help, I feel like a total moron.
Apparently I had tried something a while back in the On
Change property of the current date field and it kept
overriding whatever I tried in the previous date filed. I
forgot that was there and couldnt figure out why it wasnt
working. D'UHH!
 
Back
Top