Link to home
Start Free TrialLog in
Avatar of cekendricks
cekendricks

asked on

3709 The search key wsa not found in any record

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
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image


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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"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.
Avatar of cekendricks
cekendricks

ASKER

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!!