Closing a report during OnOpen

J

jhmosow

I have a report with the following code:

Private Sub Report_Open(Cancel As Integer)

Dim DB_Version As Variant
Dim DocName As String
Dim LinkCriteria As String

On Error Resume Next

DB_Version = DLookup("OptionValue", "Option", "OptionName =
'DefaultDatabaseLevel'")
DB_Version = InputBox("Enter database level", , DB_Version)
If IsEmpty(DB_Version) = "" Or Len(DB_Version) = 0 Then
MsgBox "Cancel pressed"
DoCmd.Close acReport, "Product Listing By Database", acSaveNo
DocName = "Inquiries/Reports Menu"
DoCmd.OpenForm DocName, , , LinkCriteria
Exit Sub
End If
Me.ServerFilter = "Database_Version = " & DB_Version
DoCmd.RunMacro "ReportToolbarShow"

End Sub

What is happening is when Cancel is pressed in the Inputbox, this does
get trapped and processes the If statement. But the DoCmd.Close does
not close the report. If Cancel is selected in the Inputbox, I want to
stop all processing of this report and go back to my menu. Any idea
what I am doing wrong or how to code this? I am using Access 2003 and
this is an ADP.

TIA
 
G

Guest

Use the "cancel" parameter ! Report will be open only if 'cancel' remains True.

bla.. bla..
if ....
cancel=False 'here your report will be close
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top