Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
231 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

715 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