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-ContinuityEnrollme nt"
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.t xt
OrderItems_20110919a.txt
ContinuityEnrollment_20110 919a.txt
ChildOrders_20110919a.txt
Orders_20110919a.txt
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
Case "Contin"
DoCmd.RunSavedImportExport
Case "OrderI"
DoCmd.RunSavedImportExport
Case "Orders"
DoCmd.RunSavedImportExport
Case "Return"
DoCmd.RunSavedImportExport
Case "Shippi"
DoCmd.RunSavedImportExport
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.t
OrderItems_20110919a.txt
ContinuityEnrollment_20110
ChildOrders_20110919a.txt
Orders_20110919a.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"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.
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.
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!!
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