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

x
?
Solved

Index problem in access

Posted on 2008-10-23
7
Medium Priority
?
494 Views
Last Modified: 2013-11-28
Hi - I'm using the attached code (which I found here) to create a table will serve as a TOC for an access report.  I created it in the Northwinds sample db with no problems, but when I try to apply to my db I get Run-time error '3800' 'TOCCategory' is not an index in this table.  I've triple checked the properties settings and "Indexed" property is set to "Yes (no duplicates)."  What am I doing wrong?

THANKS!
Option Explicit
 
Dim db As DAO.Database
Dim TocTable As DAO.Recordset
Dim intPageCounter As Integer
 
Function InitToc()
 
    Dim qd As DAO.QueryDef
 
    Set db = CurrentDb()
 
    intPageCounter = 1
 
    Set qd = db.CreateQueryDef("", "Delete * From [Table of Contents]")
 
    qd.Execute
    qd.Close
 
    Set TocTable = db.OpenRecordset("Table of Contents", dbOpenTable)
 
    TocTable.Index = "TOCCategory"
 
End Function
 
Function UpdateToc(TocEntry As String, Rpt As Report)
 
    TocTable.Seek "=", TocEntry
    
    If TocTable.NoMatch Then
        TocTable.AddNew
        TocTable!TOCCategory = TocEntry
        TocTable![page number] = intPageCounter
        TocTable.Update
    End If
    
End Function
 
Function UpdatePageNumber()
    intPageCounter = intPageCounter + 1
End Function

Open in new window

0
Comment
Question by:egj75
  • 5
  • 2
7 Comments
 
LVL 18

Expert Comment

by:jmoss111
ID: 22793534
I don't think that you can set an Index on a dao recordset.

You can't use CREATE TABLE to add a nonunique index. To add a nonunique index to an existing table use CREATE INDEX
To create an index I'd use SQL:
CREATE INDEX IX_TocCategory ON TableOfContents (TocEntry) WITH DISALLOW NULL;

Open in new window

0
 
LVL 18

Expert Comment

by:jmoss111
ID: 22793573
Object names with spaces imbedded are unnecessary and prone to cause problems and extra work.
0
 

Author Comment

by:egj75
ID: 22795779
I removed the spaces.  I'm a beginner here so I've upped the points since you'll probably have to spell things out a bit...

The code I was using generated this table when a report was opened, so the "on print' properties in various sections of the report call these various functions.  How/where would I include the sql language you provided?  

Thanks.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 18

Accepted Solution

by:
jmoss111 earned 1500 total points
ID: 22798217
Save the statement in a query and execute it immediately after the table is built.
0
 
LVL 18

Expert Comment

by:jmoss111
ID: 22814406
What would have been required to get an A from you. Didn't the solution work well for you?
0
 

Author Comment

by:egj75
ID: 22814611
No, it didn't work but I assumed it was due to the fact that I don't have a big picture understanding of programming and that your code would work for someone more knowledgable...so I wanted to give you the points but close the question.  (The report was due this morning so I had to abandon this effort and just create it manually.)  Do you not get all of the points if it's not an A?   Let me know I 'll change it - I appreciate your efforts!
0
 
LVL 18

Expert Comment

by:jmoss111
ID: 22815224
If it didn't work then you shouldn't have closed the question, but what I gave you does work. I'd rather have no points than a B and I don't want the points if a solution didn't work. I would have been glad to work through the solution with you, and the question doesn't have to be closed in X days. I'll continue working with you even though the question is closed.

Regards,

Jim
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

926 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