Skip to Content
Access™ 2007 VBA Programmer's Reference
book

Access™ 2007 VBA Programmer's Reference

by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
May 2007
Intermediate to advanced
1152 pages
30h 53m
English
Wrox
Content preview from Access™ 2007 VBA Programmer's Reference

9.5. More on Absorbing Expected Errors

As stated earlier in this chapter, sometimes a normal activity in your application results in Access encountering an error. For example, if the code behind a report cancels the On Open event, Access displays an error message. Because this is a normal event, your user shouldn't see an error message. Your application should continue as though nothing happened.

The code in the Open event of the report looks something like this:

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Error_Handler

  Me.Caption = "My Application"

  DoCmd.OpenForm FormName:="frmReportSelector_MemberList", _
  WindowMode:=acDialog

  'Cancel the report if "cancel" was selected on the dialog form.

  If Forms!frmReportSelector_MemberList!txtContinue = "no" Then
    Cancel = True
    GoTo Exit_Procedure
  End If

  Me.RecordSource = ReplaceWhereClause(Me.RecordSource,
  Forms!frmReportSelector_MemberList!txtWhereClause)

Exit_Procedure:
  Exit Sub

Error_Handler:
  DisplayUnexpectedError Err.Number, Err.Description

  Resume Exit_Procedure
  Resume

End Sub

An open selection criteria form is shown in Figure 9-8.

Figure 9.8. Figure 9-8

If the user clicks OK, the form is hidden and the report's On Open code continues. It adds the selection criteria to the report's RecordSource property and displays the report. However, if the user clicks Cancel, the form sets a hidden Continue text box to no before it ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Access 2003 VBA Programmer's Reference

Access 2003 VBA Programmer's Reference

Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein
Microsoft® Access® 2010 Programmer's Reference

Microsoft® Access® 2010 Programmer's Reference

Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison

Publisher Resources

ISBN: 9780470047033Purchase book