Date Range in Macro (1 Viewer)

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Access 2000?
I have three different reports which all work off a user specified date range. I have created a macro to run them and as long as I specify "Between And" conditions in the queries behind them the macro works fine, but you have to enter the date range three different times.

Is there a way to specify the date range once in the macro so that all the reports run for that date range???

Hope someone will help!!! :confused:
 

SOS

Registered Lunatic
Local time
Today, 02:19
Joined
Aug 27, 2008
Messages
3,517
Use a FORM for input and then refer to THAT for the values.
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Used the form and still requires to enter the date each time for each report. On the form I have a start and end date, then in the individual queries I used a "between [start date] and [end date]" expression which refers to the form fields respectively.

Why still requiring to enter dates multiple times??
 

DCrake

Remembered
Local time
Today, 10:19
Joined
Jun 8, 2005
Messages
8,632
Read this Post it will give you all the information you need to accomplish what you want.
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Thanks, but I am by no means a programer!! I follow what to enter into the individual queries, but am lost about creating the startup module and creating the new functions??

Can you guide me through this process?
 

SOS

Registered Lunatic
Local time
Today, 02:19
Joined
Aug 27, 2008
Messages
3,517
Why still requiring to enter dates multiple times??

Because you need to use the FORM referencing instead of just [Enter Start], etc.

Form referencing is like:

[Forms]![YourFormNameHere]![YourControlNameHere]
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Here is the command I tried.

Forms![Date Range Form]![Start Date] and Forms![Date Range Form]![End Date]

I placed this in the individual queries in the "Date" field criteria. When I execute the macro it steps through requiring to enter the dates 3 consecutive times to get the reports.

On the form I have two elements that are unbound; one is the start date and the other is the end date. When entering the end date it goes back to the start date. Not sure why it is not proceeding to the rest of the macro???

Is the issue in the Form and / or the macro??
 

SOS

Registered Lunatic
Local time
Today, 02:19
Joined
Aug 27, 2008
Messages
3,517
If you have this as criteria in your query and it still pops up the parameter dialog, then you have something spelled wrong or are referencing an object that is not open.

Perhaps you can post your database here and we can take a quick look.
 

Brianwarnock

Retired
Local time
Today, 10:19
Joined
Jun 2, 2003
Messages
12,701
I didn't understand this
Not sure why it is not proceeding to the rest of the macro???

Are you running the macro from a command button on the form? That is the easy way to do this
I presume that you meant

Between Forms![Date Range Form]![Start Date] and Forms![Date Range Form]![End Date]

SOS is correct in that you should check the spelling and also ensure that the form remains open, using a command button ensures that of course. :D

Brian
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Okay ... how do I post htis for you to look at??
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Okay ... here it is.

I did not see any error but another set of eyes are appreciated. Don't laugh to hard ...just learning.
 

Attachments

  • Practice.zip
    118.4 KB · Views: 382

SOS

Registered Lunatic
Local time
Today, 02:19
Joined
Aug 27, 2008
Messages
3,517
Okay, which queries are popping up the box?

Are these the ones?
q_Perioperative_Data_Query
q_DVT_Data Query
q_Complete_Advanced_Directive Query
 

Brianwarnock

Retired
Local time
Today, 10:19
Joined
Jun 2, 2003
Messages
12,701
What is happening is that the form is being opened and the queries /reports run.
The switchboard needs to open the Form, and after the dates have been entered a command button on the Form fires the macro to run the queries/reports, the macro could then close the Form.

Brian
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
The three queries that need to run to populate the reports are:

q_Advanced_Directive All Query
q_Advanced_Directive PAT Query
q_Advanced_Directive Phone Query

The others can run independently for Data Editing purposes from their associated Edit Forms.
 

SOS

Registered Lunatic
Local time
Today, 02:19
Joined
Aug 27, 2008
Messages
3,517
okay, so Brian gave the answer then.
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Ok .... then how do you make the command button trigger the macro? And how does that solve having to enter the dates several times??
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
:mad:I figured out the command button and told it to run the macro, however visually nothing happens. The reports if you click on the macro itself are there but do not open in print preview as designed. I have an "open report" after the run command but that makes no difference and finally it does not close the form at the end.:mad:
 

danbl

Registered User.
Local time
Today, 06:49
Joined
Mar 27, 2006
Messages
262
Finally I figured out the issue with the reports .... and now they work!!!!!

The only piece not working is the closing the form .... I get an error "This action can not be carried out while processing a form or report event". I click OK and the following Action Failed dialog box appears:
Macro Name = Identifies my macro
Condition = true
Actiong Name = Close
Arguments = Form, Data Range Form, Prompt

How can this be fixed??

Thanks for all your help.
 

Brianwarnock

Retired
Local time
Today, 10:19
Joined
Jun 2, 2003
Messages
12,701
Its years since I used macros and it is possible that I suggested doing something that is not allowed. :( I'll have to try and find time to design a test. It maybe that you will just have to close the form manually after you have run the reports.

Brian
 

Users who are viewing this thread

Top Bottom