Two Virtually Identical Modules, One Works, One doesn't 
Author Message
 Two Virtually Identical Modules, One Works, One doesn't

I am using Access 7.0 and I would like to generate a table of contents and
an index for a report.  I've downloaded the sample reports database from
the MS Web site and copied the table of contents module into the database
that generates the report.  The code is as follows:

Option Compare Database
Option Explicit

Dim db As DATABASE
Dim toctable As Recordset

 Function InitToc()
' Called from the OnOpen property of the report.
' Opens the database and the table for the report.
            Set db = CurrentDb()
            db.Execute "DELETE * FROM tblTableOfContents;"
'
            ' Open the table.
            Set toctable = db.OpenRecordset("tblTableOfContents",
dbOpenTable)
            toctable.Index = "Description"
         End Function

Function UpdateToc(tocentry As String, Rpt As Report)

' Called from the OnPrint property of the section containing
' the Table Of Contents entry. Updates the Table Of Contents
' entry.

    toctable.Seek "=", tocentry

    If toctable.NoMatch Then
        toctable.AddNew
        toctable!Description = tocentry
        toctable![page number] = Rpt.Page
        toctable.UPDATE
    End If

End Function

As per the sample database, I created a table to receive the generated
records and set the functions to be called from the appropriate On Format
locations in the report.  When I run the report, I receive an error stating
that the On Format expression has a "type mismatch", but Access gives no
indication of what field is involved.  As far as I can tell, all the
corresponding fields match and I can't see why I'm getting the error.

To create the report index, I created a copy of the module and the
receiving table and changed the "toctable" references to "indextable",
"tocentry" to "indexentry" and "tblTableOfContents" to "tblIndex".  I call
it from an exact copy of the original report and it works flawlessly.  I
modified it to allow duplicates in the "description" index and still had no
problems.

I decided to strip out the changes and start from scratch.  I recreated
everything and, as before, the Index module works and the Table of Contents
module doesn't. Only this time, the Index module creates two records at a
time when it should produce only one and I can't find any cause for the
duplication.

I can't tell if I'm missing something obvious, something not well
documented (that the two modules are conflicting, some keyword violation,
some initialization requirement or something else) or if this a bug or
limitation in Access itself.  Any suggestions would be greatly appreciated.



Tue, 17 Aug 1999 03:00:00 GMT  
 Two Virtually Identical Modules, One Works, One doesn't

The type mismatch error may result from how you are calling the function
UpdateToc(tocentry As String, Rpt As Report):   tocentry has to be an
explicit string  and not the control name of the description field; Rpt an
object reference, not the name of the report, thus,    
    Dim MyDescription As String
    MyDescription =Me!Description  'assumes not NULL
    UpdateToc(MyDescription,Me)
should work.  Also the code comment states that it should be in the OnPrint
event while you mention that you've placed it in the OnFormat Event.  The
difference is that the OnFormat Event may occur more than once per printed
line, thus adding the double entries.

This doesn't explain why it would work with one copy and not the next if
the code was called from the same places ,with the same controls, with the
same data (i.e., it hit the same record which might have had a NULL
description.  But it's a place to start looking.  Good luck.
GR


Quote:
> I am using Access 7.0 and I would like to generate a table of contents
and
> an index for a report...

> Function UpdateToc(tocentry As String, Rpt As Report).....
> As per the sample database, I created a table to receive the generated
> records and set the functions to be called from the appropriate On Format
> locations in the report.  When I run the report, I receive an error
stating
> that the On Format expression has a "type mismatch", but Access gives no
> indication of what field is involved...

> To create the report index, I created a copy of the module and the
> receiving table and changed the "toctable" references to "indextable",
> "tocentry" to "indexentry" and "tblTableOfContents" to "tblIndex".  I
call
> it from an exact copy of the original report and it works flawlessly.  I
> modified it to allow duplicates in the "description" index and still had
no
> problems....



Sun, 22 Aug 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Two similar templates--one works one doesn't

2. One of two functions doesn't function on Windows 95 (i does on Windows NT)

3. One out of every two .Requery don't work on my small LAN

4. One out of every two .Requery don't work on my small LAN

5. Library MDBs: One works; other doesn't

6. Activex control doesn't work when there is more then one on a form

7. Why does this work and this one doesn't

8. TWO PROJECTS, TWO EXE'S, ONE INSTALL???

9. Two Questions, one simple, one not so!

10. Two questions... one easy, one hard

11. Merge two wave file one after one

12. One Big Module or Several Small Ones?

 

 
Powered by phpBB® Forum Software