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
227 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
ID: 17045518
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
ID: 17045710
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
ID: 17046646
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
ID: 17046651
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

825 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