Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acc97 Error Item not found in collection 1

Status
Not open for further replies.

marcon

Programmer
Aug 30, 2001
21
0
0
US
This is a perplexing one. I have 2 functions made up of nearly identical code that transfers 2 identical text files into two identical tables. In fact the only difference in these two functions is one references "..ThisYear" and the other "LastYear".
One works and the other triggers the following
error : "Item not found in this collection."
This line triggers it,
Set MyQuery = MyDB.QueryDefs("qryDELETEtblAPIPDownloadThisYear")

the query by itself deletes the table contents, the columns and data types in each table are the same, I deleted the query and recreated it to no avail......any help really appreciated!
complete code appears below. thanks!

Function fncImportTableThisYear()
On Error GoTo importError

Dim MyDB As Database, MyQuery As QueryDef
Dim in_file As Variant

Set MyDB = DBEngine.Workspaces(0).Databases(0)

DoCmd.Hourglass True

in_file = InputBox("Please enter the name of This years file.", , "D:\My Documents\Commit\SCDownloadHistory\")
If Len(in_file) < 1 Then
MsgBox (&quot;You must enter a filename. Try again&quot;)
GoTo importFinish
End If


Set MyQuery = MyDB.QueryDefs(&quot;qryDELETEtblAPIPDownloadThisYear&quot;)
MyDB.Execute (MyQuery.Name)
MyQuery.Close

MsgBox (in_file)

DoCmd.TransferText A_IMPORTDELIM, &quot;APIPDownloadImportSpecification&quot;, &quot;tblAPIPDownloadThisYear&quot;, in_file, False




MsgBox &quot;Finished! &quot;

GoTo importFinish

importError:
MsgBox (&quot;Error is &quot; & Error(Err) & &quot;!!!! TERMINATING!!!!&quot;)
DoCmd.Hourglass False
End

importFinish:

DoCmd.Hourglass False

End Function

' Purpose : provide error free links for tblAPIPDownloadThisYear
' Note : data types are not working, must change finent
 
Hmmm,

Should not your set MyQuery state

Set MyQuery = MyDB.CreateQueryDef(&quot;&quot;, &quot;qryDELETEtblAPIPDownloadThisYear&quot;)

In any case, why not use a SQL statement instead. You then no longer need MyDB nor MyQuery

These are the only 3 statements you need
DoCmd.SetWarnings False
DoCmd.RunSQL (&quot;DELETE * FROM tblAPIPDownloadThisYear)
DoCmd.SetWarnings True

John Ruff - The Eternal Optimist :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top