Pausing VBA Execution Until Form Closes

  • Thread starter Thread starter Jeff Garrison
  • Start date Start date
J

Jeff Garrison

All -

I have a form where I want to launch a report. I have another form where
the user enters the date range for the report. Once the parameters have
been entered, I'd like to have the form close and open the report. My
question is...is there a way to pause the VBA call of opening the report
until the date parameter form is closed, then resume opening the report.

I'm using Access 07.

Thanks.

Jeff
 
Jeff,

Open the form in Dialog mode. That is a characteristic of this mode. The
method would look like this:


DoCmd.OpenForm "SomePopupForm", , , , , acDialog


God Bless,

Mark A. Sam
 
Jeff:

Open the second form in dialogue mode using the acDialog option for the
WindowMode argument of the OpenForm method, e.g.

DoCmd.OpenForm "frmReportParameters", WindowMode:=acDialog

Any code after this line will not be executed until the frmReportParameters
form has been closed (or hidden).

You could pass the parameter values back to the calling form, which you
could do by assigning them to unbound hidden text box controls on the calling
form, which can then be referenced when opening the report with code in the
calling form's module. You could do this in the parameter form's Close event
procedure. A simpler method is to open the report with code in the
parameters form's Close event procedure. You can pas the report name from
the calling form to the parameters form via the OpenArgs mechanism. I've
assumed a constant report name below but you could of course use a variable
if the calling form allows a choice of reports. So the calling form's code
would be like this:

' open dialogue form passing report name to it
DoCmd.OpenForm "frmReportParameters", _
WindowMode:=acDialog, _
OpenArgs:= "MyReport"
' close this form
DoCmd.Close acForm, Me.Name

The code for the parameters form's Close event procedure might be like this:

Dim strCriteria As String

strCriteria = "[MyDate] >= #" & _
Format(Me.txtStartDate, "mm/dd/yyyy") & _
"# And [MyDate] < #" & _
Format(DateAdd("d", 1, CDate(Me.txtEndDate)), _
"mm/dd/yyyy") & "#"

DoCmd.OpenReport Me.OpenArgs, _
View:=acViewPreview, _
WhereCondition:=strCriteria

where txtStartDate and txtEndDate are the two text box controls on the form
in which the start and end of the date range are entered. Note that the
range is defined as being on or later than the start date and before the day
following the end date. This caters for any values in the MyDate column
which might have non-zero times of day. Such values can all too easily creep
in without you being aware of it unless you have specifically taken steps to
prevent this in the table definition. Any rows with such values on the final
day of the range would otherwise not be returned.

Ken Sheridan
Stafford, England
 
If the parameters are on the form and you close it before the report opens,
the report probably will fail.

Instead of closing the form, why not just set it to invisible. Using
something below on the button that you use to open the report.

Me.Visible = False
 
Thanks....new knew about that one...

Jeff

Mark A. Sam said:
Jeff,

Open the form in Dialog mode. That is a characteristic of this mode. The
method would look like this:


DoCmd.OpenForm "SomePopupForm", , , , , acDialog


God Bless,

Mark A. Sam
 
Back
Top