Closing a report

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

I have a report that fires from a button on a reports menu
form. This report, when opened, opens a form in which the
user enters criteria for that report. The form has an OK
button which continues to run the report, and a Cancel
button which closes the form but the report still prints.
VB code controls everything, but I can't figure out how to
close both the criteria form and the report so it won't
print when the Cancel button is pressed.
 
I have a report that fires from a button on a reports menu
form. This report, when opened, opens a form in which the
user enters criteria for that report. The form has an OK
button which continues to run the report, and a Cancel
button which closes the form but the report still prints.
VB code controls everything, but I can't figure out how to
close both the criteria form and the report so it won't
print when the Cancel button is pressed.

If you are opening the parameter form from the Report's Open event,
you can use the Report's Open event's Cancel argument to close the
report if the form is not open.

In Access 2002 or newer:
DoCmd.OpenForm "ParameterForm" , , , , , acViewPreview
If Not CurrentProject.AllForms("ParameterForm").IsLoaded Then
Cancel = true
End If
==========

In Access 97 or older:
DoCmd.OpenForm "ParameterForm" , , , , , acViewPreview
If Not IsLoaded("ParameterForm") Then
Cancel = True
End If
=====
Then, in Access 97, copy and paste into a Module, the below code:

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open
Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
 
Back
Top