Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    46

    Unanswered: Accessing a Report Object in Access using VBA

    I am having a major problem acessing a Report within an Access project by using code. I am getting the following error:
    Run-time error 2457. The number used to refer to the report is invalid.

    The ways that I am trying to refer to the report, which is called rptReport, are:
    (a). MsgBox CurrentProject.AllReports.Application.Reports(0).N ame
    (b). MsgBox Access.Application.Reports("rptName").Name
    (c). MsgBox MsgBox Reports.Item(0).Name


    I have tried about 10 different ways of trying to do this and I cannot get this to work. Could someone please help. This is kind of urgent.

    Thanks.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Curriously these both return different report names. But anyhoo:

    Code:
    ?Application.Currentdb.Containers("Reports").Documents(0).Name
    
    ?CurrentProject.AllReports.Item(0).Name
    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    BTW - just realised what you have tried -
    there are two types of "report" you can access in code -

    Persistant Reports
    Open Reports

    The code I have posted looks in the Reports Container - this contains all the persistent (saved) reports.

    Application.Reports

    is a Collection of all the open reports. As such the index is dynamic and changes over time (the first report opened is 0 and subsequent ones count up - if a report is closed the reports are reindexed).

    So:
    Code:
    Application.Currentdb.Containers("Reports").Documents(0).Name
    <>
    Code:
    Application.Reports.Item(0).Name
    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by pootle flump
    Curriously these both return different report names.
    Code:
    ?Application.Currentdb.Containers("Reports").Documents(0).Name
     
    ?CurrentProject.AllReports.Item(0).Name
    The former is alphanumeric but the latter seems random - nothing to do with name or creation date. How peculiar!
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •