Solved

"Search Key Not Found" Error when running macro

Posted on 2008-06-25
12
454 Views
Last Modified: 2013-11-27
jimpen helped me with some coding some weeks (or months) ago, but I am still having trouble making it work.

I get an "Run Time Error '3709': The Search Key was Not Found in Any Record "error message when running the sub NewParetoGen()

Can anyone tell me what is going wrong?

This is supposed to transpose a query into a table. I have attached it below.
Option Compare Database
 

Public Sub NewParetoGen()
 

'Delete Existing Tables
 

'Declare strSource As String, strTarget As String

    Dim strSource As String

    Dim strTarget As String
 

'set them equal to the intended arguments

    strSource = "FifteenthStWoodqryFPYPareto"

    strTarget = "FifteenthStWoodFPYParetoTable"
 

    'If CheckTableExists(strTarget) = True Then

        'DoCmd.DeleteObject acTable, strTarget

    'End If
 

    Call NewTransposer(strSource, strTarget)

 

End Sub
 

Function NewTransposer(strSource As String, strTarget As String)

 

   Dim db As DAO.Database

   Dim tdfNewDef As DAO.TableDef

   Dim fldNewField As DAO.Field

   Dim rstSource As DAO.Recordset, rstTarget As DAO.Recordset

   Dim i As Integer, j As Integer

 

   'On Error GoTo Transposer_Err

 

   Set db = CurrentDb()

   Set rstSource = db.OpenRecordset(strSource)

   rstSource.MoveLast

 

   ' Create a new table to hold the transposed data.

   ' Create a field for each record in the original table.

   Set tdfNewDef = db.CreateTableDef(strTarget)

   For i = 0 To rstSource.RecordCount

      Set fldNewField = tdfNewDef.CreateField(CStr(i + 1), dbText)

      tdfNewDef.Fields.Append fldNewField

   Next i

   db.TableDefs.Append tdfNewDef

   tdfNewDef.Fields(0).Name = "Defect"               ' <-- added

   tdfNewDef.Fields(1).Name = "QTY"
 

If DoesTblExist(strTarget) = True Then

     DoCmd.SetWarnings False

     DoCmd.DeleteObject acTable, strTarget

     DoCmd.SetWarnings True

End If
 

DoCmd.CopyObject , strTarget, acTable, strSource
 

End Function
 

'-----------------------------------------------------------

'Added function:

'-----------------------------------------------------------

Public Function DoesTblExist(strTblName As String) As Boolean

    On Error Resume Next

    Dim db As Database, tbl As TableDef

    Set db = CurrentDb

    Set tbl = db.TableDefs(strTblName)

    If Err.Number = 3265 Then   ' Item not found.

       DoesTblExist = False

       Exit Function

    End If

    DoesTblExist = True

End Function

Open in new window

0
Comment
Question by:Rex85
  • 6
  • 5
12 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 21870399
Guaranteed record corruption ... run this procedure.

Try a Compact and Repair.  If that fails, try this:

A **DeCompile** may help here ...

But first, if you have not already:
Check for any **Missing References via the VBA Editor>>Tools>>References ....

Then, follow this procedure:

****
0) **Backup your MDB BEFORE running this procedure**
****
1) Compact and Repair the MDB, as follows:
Hold down the Shift key and open the MDB, then from the menu >>Tools>>Database Utilities>>Compact and Repair ...
Close the mdb after the Compact & Repair.
2) Execute the Decompile (See example syntax below) >> after which, your database will reopen.
3) Close the mdb
4) Open the mdb and do a Compact and Repair (#1 above).
5) Close the mdb.
6) Open the mdb:
    a) Right click over a 'blank' area of the database window (container) and select Visual Basic Editor. A new window will open with the title 'Microsoft Visual Basic' ... followed by then name of your MDB.
    b) From the VBA Editor Menu at the top of the window:
       >>Debug>>Compile
        Note ... after the word Compile ...you will see the name of your 'Project' - just an fyi.

7) Close the mdb
8) Compact and Repair one more time.

*** Executing the DeCompile **EXAMPLE**:
Here is an **example** of the command line syntax  (be SURE to adjust your path and file name accordingly) before executing the decompile:

Run this from Start>>Run, enter the following command line - **all on one line** - it may appear like two lines here in the post:
Also, the double quotes are required.

"C:\Program Files\Microsoft Office\Office\Msaccess.exe" /decompile "C:\Access2003Clients\YourMdbNameHERE.mdb"

For more detail on the Decompile subject ... visit the Master on the subject (and other great stuff) Michael Kaplan:

http://www.trigeminal.com/usenet/usenet004.asp?1033

mx
0
 

Author Comment

by:Rex85
ID: 21870417
Does "Guaranteed record corruption" mean that I have record corruption, or that this NewParetoGen sub is a guarantee that I will corrupt them?
0
 
LVL 75
ID: 21870449
Sorry ...

It (99% if the time) means that one or more fields in one or more records are corrupt.  Probably just one field in one record.  I see this a LOT.

mx
0
 

Author Comment

by:Rex85
ID: 21874405
I tried the suggestions you had with no effect.

One thing I noticed, in the last line...

DoCmd.CopyObject , strTarget, acTable, strSource

of the sub, strSource is a Query, not a table. I changed acTable in that line to acQuery, and now I don't get the "Search key not found" error. It still doesn't work, but I don't get that error. I either get nothing, as in executes, but has no visible output, or I get a "table already exists" error at the line

db.TableDefs.Append tdfNewDef

0
 
LVL 75
ID: 21875919
Can you zip up the MDB, then attach the file for upload here  ... removing any sensitive data of course?  

Give specific info as to how to reproduce the problem, which table, etc.

mx
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Rex85
ID: 21877392
OK. The whole thing is about 50MB, so I'll have to pull out just the part being dealt with here. Thanks.

Rex
0
 
LVL 75
ID: 21877428
Be sure to Compact & Repair, then Zip up.  Post info here how to reproduce the issue - be explicit.

thx.mx
0
 

Author Comment

by:Rex85
ID: 21877786
Running the sub

Public Sub NewParetoGen()

in the jimpen Module generates the attached error and the debug higlights the line as in the attached file. It always happens.

The query involded here is querying a union query which combines two production lines into a plant. (the Wood plant) It then creates a sum of each of the various defect types for a given period of time for that plant.

The problem is that the query is one row with columns. I need the data in two columns with multiple rows in order for it to feed Minitab, which makes the Pareto charts. Hence the attempt at a Transposing procedure.

I don't have a zipper, so I made a back-up and then stripped out everything except the files in question for this problem. It made it pretty small.
KO-Quality-Master-2008-Linked-20.mdb
Error-Generated-6-26-2008.bmp
debug-line-6-26-2008.bmp
0
 
LVL 75
ID: 21877841
but when and how do you get this error:

" "Run Time Error '3709': The Search Key was Not Found in Any Record"

mx
0
 

Author Comment

by:Rex85
ID: 21877993
I can't recreate that error now. It only gives me the Table already exists error. The only thing I did was change that acTable to acQuery and run the NewParetoGen sub. Since then, I only get the table error, not the index error. I changes the acQuery back to acTable, but still, only the Table error.
0
 

Author Closing Comment

by:Rex85
ID: 31470793
This was a while ago. This didn't realy fix the problem, but I believe it pointed me in the right direction. Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now