Solved

3709 The search key wsa not found in any record

Posted on 2011-09-21
4
1,312 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 119

Accepted Solution

by:
Rey Obrero 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

16 Experts available now in Live!

Get 1:1 Help Now