Stopping execution of code while print previewing reports access 2010
Posted on 2016-11-28
Here is my scenario:
I have a form that has two subforms on it. These subforms (views as datasheets on the main form) are bound to a temp table that stores the data until I post. Once I post, it posts to a table and then deletes the data from the temp table.
I also have a report that a user can preview/print when after they post the information. This report takes data directly from the form and has two subreports that queries the same temp table to populate the subform's information. The issue is when a user clicks on post, it asks the user if they want to preview the report. If they click yes, the reports appears. The execution also continues to post the information. Herein lies my issue. While the report previews correctly (with all of the subreport's data from the temp table, if the use then prints the report the main report info is there, but the subreport's info is gone (because the execution posted the data and deleted the info from the temp table).
So I either need to do one of two things: Stop the execution of my code until the user either closes the preview, or take the information directly from the subform (similar to how I am taking it from the main form) to populate the subreport's information. Not too sure which I prefer, but I just need to have the data still in the report when it is printed.
I tried to add a Do while CurrentProject.OpenReport("reportName").IsLoaded = true, but it never displayed the report and created an infinite loop. Also tried an If condition to pop up a msgbox asking if the user wanted to continue with the posting, but this didn't work either.
Any thoughts and help would be tremendously appreciated.