Solved

3709 The search key wsa not found in any record

Posted on 2011-09-21
4
1,354 Views
Last Modified: 2012-08-14
I have a bit of real simple VBA that is raising an error that I can't figure out.  The purpose of the procedure is simply to import (via saved imports that append to existing tables) dependant upon the first six letter of the file name.  The folder containing the files is passed in as an argument to the procedure which is called from another procedure that saves the files from email attachments.  Here is the Sub that raises the error:

Public Sub ImportTextFiles(strFolder As String)

    Dim strFile As String
    Dim strShort As String
   
    strFile = Dir(strFolder)
   
    strShort = Left(strFile, 6)
   
    While strFile <> ""
         
         Select Case strShort
            Case "ChildO"
                DoCmd.RunSavedImportExport "Import-ChildOrders"
            Case "Contin"
                DoCmd.RunSavedImportExport "Import-ContinuityEnrollment"
            Case "OrderI"
                DoCmd.RunSavedImportExport "Import-OrderItems"
            Case "Orders"
                DoCmd.RunSavedImportExport "Import-Orders"
            Case "Return"
                DoCmd.RunSavedImportExport "Import-ReturnsCancels"
            Case "Shippi"
            DoCmd.RunSavedImportExport "Import-Shipping"
        End Select
       
        Kill strFolder & strFile
               
       Debug.Print "Killed " & strFile
     Wend

End Sub

The error is: Run-time error '3709': The search key was not found in any record.

When the error occurs the first line containing the RunSavedImportExport command is highlighted.  

I am running Windows 7 with Access 2010 and this is a .accdb file of only 11.7Mb

I have tried C & R

The names of the only files in the folder are:

Shipping_20110919a.txt
ReturnsCancels_20110919a.txt
OrderItems_20110919a.txt
ContinuityEnrollment_20110919a.txt
ChildOrders_20110919a.txt
Orders_20110919a.txt
0
Comment
Question by:cekendricks
4 Comments
 
LVL 75
ID: 36577474

99% of the time, this error means one or more fields in one or more records is/are corrupted.

First thing to try is do a Compact & Repair on the db.  Make a backup first.

mx
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36577684
test this revision
Public Sub ImportTextFiles(strFolder As String)

    Dim strFile As String
    Dim strShort As String
   
    strFile = Dir(strFolder)
   
  '  strShort = Left(strFile, 6)  'Moved inside loop
   
    While strFile <> ""
          
           strShort = Left(strFile, 6)           

         Select Case strShort
            Case "ChildO"
                DoCmd.RunSavedImportExport "Import-ChildOrders"
            Case "Contin"
                DoCmd.RunSavedImportExport "Import-ContinuityEnrollment"
            Case "OrderI"
                DoCmd.RunSavedImportExport "Import-OrderItems"
            Case "Orders"
                DoCmd.RunSavedImportExport "Import-Orders"
            Case "Return"
                DoCmd.RunSavedImportExport "Import-ReturnsCancels"
            Case "Shippi"
            DoCmd.RunSavedImportExport "Import-Shipping"
        End Select
       
        Kill strFolder & strFile
               
       Debug.Print "Killed " & strFile

        strFile=dir()   'ADD this line

     Wend

End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:pdebaets
ID: 36577970
"The Search Key was not found in any record"

Probably there are some bad records corrupting the table. Look for "chinese" characters in text fields. You won't be able to delete these records unless you temporarily remove the table indexes, delete the records, then replace the indexes.
0
 

Author Closing Comment

by:cekendricks
ID: 36581167
Once again Capricorn1 you hit the nail on the head.  I see the how the placement of the strShort = Left... line in my code was just a dumb mistake, but I was forced to go back and reevaluate my conception of the Dir function.  That is where I really had a major misunderstanding, in not realizing that it had to be recalled with no arguments to get subsequent matching files from the referenced directory...Thanks a million!!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

810 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