db As DAO.Database gives me errors

K

kris1616

I am trying to create a table of contents for a report. I am using code
straight off of Microsoft's knowledge base. When I compile the code, I get
the error that user defined type not defined, and it points to db As
DAO.Database. Any ideas why this would happen? Here's the rest of the code in
case that's helpful.

Option Explicit

Dim db As DAO.Database
Dim TocTable As DAO.Recordset
Dim intPageCounter As Integer
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 [tblAssignSpreadTOC]")

qd.Execute
qd.Close

'Open the table.
Set TocTable = db.OpenRecordset("tblAssignSpreadTOC", dbOpenTable)

TocTable.Index = "Description"
End Function

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top