Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

3709 The search key wsa not found in any record

Posted on 2011-09-21
4
Medium Priority
?
1,433 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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