Solved

Overcoming run-time error 2465 application object or defined error in viewing Access report with break on all errors.

Posted on 2006-07-05
4
226 Views
Last Modified: 2008-02-01
Basically I have all my Access reports accessing the following function upon when a PageFooterSection_Format is performed.
However not all reports have a label called lblLegend - thus where I have Else
    objReport.lblLegend.Properties("Visible") = False I get a run-time error 2465 application object.
I absolutely cannot afford to get this error and have the On Error Resume Next does not work for some situations.
Is there anyway I can test to be sure that lblLegend exists before accessing the properties?

Thank you,

Stephen


Public Function fncMyFooterFunction(objReport As Object)
On Error Resume Next

If Forms!frmReports!chkLegend = True Then
    objReport.lblLegend.Properties("Visible") = True
    objReport.LineLegend.Properties("Visible") = True
    objReport.lblLegend.Properties("Top") = 1020
    objReport.PageFooterSection.Height = 1.0833
    objReport.PageFooter2.Height = 1.0833
  Else
    objReport.lblLegend.Properties("Visible") = False
    objReport.LineLegend.Properties("Visible") = False
    objReport.PageFooterSection.Height = 0
    objReport.lblLegend.Properties("Top") = 0
    objReport.PageFooter2.Height = 0.5
End If

End Sub
0
Comment
Question by:stephenlecomptejr
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
Comment Utility
A simple function, may not be elegant but does work

Public Function CheckFieldExists(ByVal obj As Object, ByVal sName As String) As Boolean

    Dim ctl As Control
   
   
    CheckFieldExists = False
    For Each ctl In obj.Controls
        If ctl.name = sName Then CheckFieldExists = True
    Next
End Function


Call it passing in the form or report object, along with name of control
It returns true if it exists, false otherwise

Example usage - I have a form called form9, and a control called Text0

    MsgBox CheckFieldExists(Forms("form9"), "Text0")



So I guess u could do


if CheckFieldExists(objReport, "lblLegend") = True then objReport.lblLegend.Properties("Visible") = True
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
the other way of course is to set it, then check the err.number (u need on error resume next set)
or have a generic error handler and ignore the control not found error
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
In the PageFooter, loop thru all the controls in the report to test if any has the name 'lblLegend'.  If so, test for visible and act accordingly.  ie.

For each ctl in Me.Controls
  If me.ctl.name = 'lbLegend"
    <Run code if true>
  Else
    <Runcode if false>
End If
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
Sorry, that should be:

For each ctl in Me.Controls
  If me.ctl.name = "lbLegend"
    <Run code if true>
  Else
    <Runcode if false>
End If
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now