Go Premium for a chance to win a PS4. Enter to Win

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
?
233 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 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

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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.

824 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