View Full Version : Default Date


dkuntz
04-16-2002, 07:47 AM
I am running a report based on a date query.
Currently in the "Criteria" section for the [InvoiceDate]field I have Between[Enter start date: ] And [Enter end date: ].

Preferably I want to have a default date DateAdd("d",-3,Date()) displayed so the user can just click OK. How do I display this similar to how it is display when you use the "Between" operator?

Thank you
Derek

David R
04-16-2002, 08:31 AM
Make a popup form instead of using parameter boxes. Whatever you were using to run your query, run this instead:
DoCmd.OpenForm "PopupFormName"

Your popup form will have NO data source, but will have two text boxes and two buttons.
1st box: Default Value: Date()-3
2nd box: Default Value: Date() (or whatever)
1st button: Text: Run (or whatever)
In the Click event put this in the code builder: DoCmd.OpenQuery "QueryName"
2nd button: Text: Cancel, or whatever.
In the Click event for thus button: DoCmd.Close

Now you need to change your query a bit to refer to this form instead of parameters.
In the criteria for [InvoiceDate]:
Between Forms!PopupFormName.TextBox1Name And Forms!PopupFormName.TextBox2Name

Make sense? You can even put validation on the text boxes to make sure they are valid dates before you run your query.

HTH,
David R

dkuntz
04-16-2002, 09:56 AM
It looks like your suggestions will work, however let me give you a little more information and you can tell me if this changes anything.

I have a checkbox on a form. In the checkbox OnClick event it calls a macro. The macro is used to email the report almost instantly. The macro's object type and name is a report and the report name. The report calls the query mentioned in my first question.

As it is now, when the user opens the form and clicks on the checkbox for a certain customer account they are then promted to type in a date range. This is where I want to automatically have a default date. The application is only opened on Monday and the date would be the previous Friday. Does any of this change your orignal answer?

Thanks for replying!

Derek

David R
04-16-2002, 11:00 AM
There's probably a way to automate this a little more but I'll need more information. Is last Friday the Start date or End date? Can they choose to run the report for a different day than last Friday? How is the other date determined?

Also if you're using Macros you'll have to figure out the Macro equivalent to the DoCmd.OpenXXXXXX code I gave you, or start trying to use VBA code. It's not that scary, I promise!

Post back and someone will help you figure it out I'm sure,
David R

dkuntz
04-16-2002, 11:24 AM
I don't even really need a date parameter. The default date just needs to be Friday, unless it's the end of the month then the default date would be the last day of the month.

David R
04-16-2002, 12:48 PM
You had two dates though, which one is which?

You can generally get "last Friday" with this formula: DateAdd("d",6-Weekday(Date()),Date())

Which one takes precedence, last day of the month or Last Friday? That will determine how you populate your text box(es?).

David R