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
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

734 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