Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

3709 The search key wsa not found in any record

Posted on 2011-09-21
4
Medium Priority
?
1,420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

730 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