Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programatically Close Report

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
In ReportA, I have a test in the detail_format event that, when evaluated as true, will open ReportB. What I would like to do is then close ReportA.

I have tried 'DoCmd.Close acReport, "ReportA"' but receive run time error 2585 "This action can't be carried out while processing a form or report event"

Also tried to set the Cancel = True but that only stops the formatting of ReportA.

Tried the 'DoCmd.Close acReport, "ReportA"' in the Report_Open event of ReportB but that does not seem to execute; also put the close in the format event and received error 2585.

Is there a way to do this?

Thanks.



Larry De Laruelle

 
I doubt there is a clean way to do this unless you run the code on the report's on open event (and even then I'm not sure) in which case you can't use the logic in the report.

So either use the on open event of the report or handle it before wherever you run report A. The condition that is true can probably be made in a query. Then you could use a dlookup to get the value and test to determine if you want to open the other report and close Report A (I recommend ME.Name instead of the literal if you are using the on open event).
 
lameid:

What I am testing is the size of a 'can grow' control in the detail section and the test needs to happen in the on print event.

The report is an invoice with horizontal and vertical lines and the description may be longer than the set field size. I've not found a way to programatically adjust the vertical lines so I've used two versions of the report - one regular and one long.

I had thought of determining the length of the field by getting the number of characters but that is not practical because the descriptions contain short lines and extra carriage returns.

Thanks for the response and if anything else occurs to you, please let me know.

Larry De Laruelle

 
I have found a solution. It's not as elegant as I would have liked, but it works.

Created a global variable to hold the value for the field height.

In the event to open ReportA, after the DoCmd.Open, I test the value of the global variable and if it exceeds the established maximum I issue the DoCmd.Close acReport, "ReportA".

In the on print event of ReportA I assign the actual height to the global variable, test it and, if needed, open ReportB.

It sounds somewhat circular but it works.

Larry De Laruelle

 
It sounds like a solution although I would think On Format would be better than On print.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top