Results 1 to 7 of 7
  1. #1
    Davi is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2018
    Posts
    4

    create table of contents for Access report

    I am trying to create a table of contents for an Access report using the following script. I added =InitToc() at report on open, Case number header =UpdateToc([STA_N],[Report]), and page footer =UpdatePageNumber(). But I got error message The object doesn't contain the automation object 'STA_N'.




    Any body can help me?

    Thank you in advance!

  2. #2
    Davi is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2018
    Posts
    4
    Forgot posting the script.

    Option Explicit


    Dim db As DAO.Database
    Dim TocTable As DAO.Recordset
    Dim intPageCounter As Integer
    'Create the following procedure:
    Function InitToc()
    'Called from the OnOpen property of the report.
    'Opens the database and the table for the report.
    Dim qd As DAO.QueryDef

    Set db = CurrentDb()

    'Resets the page number back to 1
    intPageCounter = 1
    'Delete all previous entries in Table of Contents table.
    Set qd = db.CreateQueryDef("", "Delete * From [Table of Contents]")

    qd.Execute
    qd.Close

    'Open the table.
    Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)

    TocTable.Index = "numsta"
    End Function


    Function UpdateToc(TocEntry As String, Rpt As Report)
    'Call from the OnPrint property of the section containing
    'the Table Of Contents numsta field.
    'Updates the Table Of Contents table.
    TocTable.Seek "=", TocEntry


    If TocTable.NoMatch Then
    TocTable.AddNew
    TocTable!numsta = TocEntry
    TocTable![Page] = intPageCounter
    TocTable.Update
    End If
    End Function
    Function UpdatePageNumber()
    intPageCounter = intPageCounter + 1
    End Function

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I've never seen this code before but it looks worth exploring for some of my own reports.
    Have you tried downloading the example db from the page from where this code originates
    https://support.microsoft.com/en-gb/...&wa=wsignin1.0
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    Davi is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2018
    Posts
    4
    Yes. I used the code that you refer to.

    But it doesn't work well.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    The link I provided mentions a sample database using that code but the link seems to be broken
    If you google something like 'toc access report' you will get other hits asking about the same code
    I'm answering on a tablet so can't test the code myself

    This link describes another approach https://office-watch.com/2015/access...ntents-report/

    HTH
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Davi is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2018
    Posts
    4
    A sample from this forum works. But when I set my own, it doesn't. for instance, the sample use case_name in TOC table. I couldn't change to other name. I also question there are some setting in table or report that I didn't set it right.

    Could any one can help me?


    Thanks!

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Suggest you supply a link to the working example on this forum

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 02-02-2015, 12:03 AM
  2. How to Create a Table of Contents?
    By McArthurGDM in forum Reports
    Replies: 1
    Last Post: 08-13-2014, 09:17 AM
  3. Replies: 5
    Last Post: 04-05-2014, 08:52 PM
  4. Navigable Table of Contents for a Report
    By DepricatedZero in forum Reports
    Replies: 2
    Last Post: 05-30-2013, 12:18 PM
  5. Replies: 5
    Last Post: 04-18-2012, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums