dkuntz
04-23-2002, 10:49 AM
Please let me know if this is possible.
I need to check if today's date is the first of the month, if it is I need to use the last date of the previous month, otherwise the default will be
DatePart("d",-3,Date())
Any help would be appreciated!
dkuntz
04-23-2002, 12:30 PM
Let me word this better:
This report is only ran on Monday's or the first day of a new Month.
So when we open this form on Monday or the first day of the Month I would need a default value to be displayed in a date textbox (txtDate). This is where I am having some trouble. I would need the expression to see if it's the first of the month, if it is then display the last day of the previous month otherwise display the fifth day of the week (Friday).
I aplogize if I haven't explained this well enough.
David R
04-24-2002, 10:16 AM
This looks like a continuation of our earlier thread here: http://www.access-programmers.co.uk/ubb/Forum3/HTML/003461.html
Try this:
Assuming this is an unbound form you use to run a query or report or something similar, try this in Form_Load:
If Day(Date()) = 1 Then
Me.txtDate = DateAdd("d",-1,Date())
Else
Me. txtDate = DateAdd("d",6-Weekday(Date()),Date())
'or DateAdd("d",-3,Date()) if you're absolutely sure it's Monday
End If
Question: What happens when the 1st is on a Sunday?
[This message has been edited by David R (edited 04-24-2002).]
dkuntz
04-24-2002, 07:51 PM
Thanks for helping David. Good question about "what if the first is on a Sunday?"
Could I just manually change the date to the last day of the previous month? Sorry I didn't reply earlier, I work very strange hours.
I like your idea about putting code in the form load event. I much prefer writing code in VB anyway.
Thanks David!
David R
04-25-2002, 06:38 AM
Yes, you can of course leave the text box available to change before the person runs the report. I assume all of this is going on a form that someone hits 'run' or something similar from.