logikillox.blogg.se

Word 2016 table of contents hyperlink levels
Word 2016 table of contents hyperlink levels













  1. Word 2016 table of contents hyperlink levels code#
  2. Word 2016 table of contents hyperlink levels download#

The version number may differ, depending on your Office version check the version you have.

If you import code or objects into a database of your own, you may need to set one or more of these references. The code in the sample database needs the following references (in addition to the default references): Public Function GetTOCPages() As Integer On Error GoTo ErrorHandler 'Get number of TOC pages and save to a custom database property strReport = "rsubTOC" DoCmd.OpenReport reportname:=strReport, _ View:=acViewPreview Set rpt = Reports(strReport) intTOCPages = CInt(rpt!.Value) Debug.Print "TOC Pages: " & intTOCPages DoCmd.Close objecttype:=acReport, _ objectname:=strReport strPropertyName = "TOCPages" lngDataType = dbInteger Call SetProperty(strPropertyName, lngDataType, intTOCPages) ErrorHandlerExit: Exit Function ErrorHandler: MsgBox "Error No: " & Err.Number _ & " in GetTOCPages procedure " _ & "Description: " & Err.Description Resume ErrorHandlerExit End Function This custom database property is saved from this procedure, which is run from the report’s Open event, which also puts up a message box asking if you want to recreate the Table of Contents, and runs the GetReportPages procedure if you click Yes. TxtTOCPages has this control source: =GetProperty("TOCPages","") Here are the control sources of the txtCorrectedPageNo and txtCorrectedNumPages textboxes referenced in the above expression: =Val(.)-Val(.) =Val(.)-Val(.) ),"Page " & RomanNo(.))Īs is often the case on Access reports, I sometimes found it necessary to reference the value of a textbox, rather than the actual value that is the control source of the textbox. The page number expression is: =IIf((>.)=True,("Page " &.

word 2016 table of contents hyperlink levels

The expression that creates the page numbers references several invisible textboxes in the report footer (the yellow ones – that is my convention for invisible controls):

See download code below for entire code including error handler. MatchAllWordForms = False End With Set sel = appWord.Selection 'Retrieve page number from Word document intPageNumber = sel.Information(wdActiveEndPageNumber) Debug.Print "Customer ID " & strCustomerID _ & " page no.: " & CStr(intPageNumber) ! = intPageNumber. AddNew ! = strCustomerID 'Find Customer ID in Word document With. CheckSpellingAsYouType = False End With Do While Not rstSource.EOF strCustomerID = rstSource! With rstTOC. The procedure listed below does the work of saving the page numbers to the table used as the subreport’s record source: Public Function GetReportPages() On Error GoTo ErrorHandler 'Close existing RTF file if necessary strCurrentPath = & "\" strWordRTFFile = strCurrentPath & "Orders.rtf" Debug.Print "Word RTF file: " & strWordRTFFile On Error Resume Next Set doc = appWord.Documents(strWordRTFFile) If Not doc Is Nothing Then doc.Close savechanges:=wdDoNotSaveChanges End If On Error GoTo ErrorHandler 'Export Orders report to Word RTF file strReport = "rptOrders" DoCmd.OutputTo objecttype:=acOutputReport, _ objectname:=strReport, _ outputformat:=acFormatRTF, _ outputfile:=strWordRTFFile, _ autostart:=False Set doc = (strWordRTFFile) doc.Select 'Clear old TOC records strTOCTable = "tblTOCPageNos" strSQL = "DELETE * FROM " & strTOCTable DoCmd.SetWarnings False DoCmd.RunSQL strSQL 'Set up recordsets of customer codes to search for and table 'for storing Customer IDs and page numbers strQuery = "qr圜ustomerIDs" Set rstSource = CurrentDb.OpenRecordset(strQuery) Set rstTOC = CurrentDb.OpenRecordset(strTOCTable) appWord.Visible = True 'Turn off spelling and grammar checking With appWord.Options. Here is the first page of the report with a Table of Contents:Īnd here is the first page of the body of the report:

  • Make a complex expression to display Roman numerals for the TOC page numbers, and Arabic numerals (starting with 1) for the regular page numbers.
  • Make a copy of rptOrders (rptOrdersWithTOC), and insert the subreport into the report header.
  • Create a subreport (rsubTOC) whose record source is a query based on the table filled with current Customer ID and page number values.
  • Using VBA code working with the RTF document and a recordset of CustomerIDs for customers who have orders, search for each CustomerID and get the number of the page it is on, and save the CustomerID and page number to a table.
  • word 2016 table of contents hyperlink levels

    Here is a high-level description of how I did it:

    word 2016 table of contents hyperlink levels

    This is a long report, so it would be handy to have a table of contents listing the page for each Customer ID. The sample database for this article, Table of Contents Report (AA 236).accdb, has tables from the old Northwind sample database, and a standard stepped Orders report:

    word 2016 table of contents hyperlink levels

    Access reports don’t have such a feature, but I managed to create one using VBA code, custom database properties and some Word features. Word has a sophisticated Table of Contents feature that automatically creates a table of contents from designated headings in a document. By Helen Feddema Access versions: 2007-2013















    Word 2016 table of contents hyperlink levels