project runtime errors 3265 and 2162

I named a database as Report (stupid thing that I did in the beginning!!!!!) and for unobvious reasons I was getting errors while trying to use the Report in the VBA. So I made a brand new project in MSaccess and copied all the modules and class files to this new project. I also copied the forms. Now the statements that worked fine in the old project do not work in this project.

I am using the following statements

First I use:

"Dim strSQL As String
strSQL = "SELECT  tblFATS.* FROM tblFATS WHERE ID1 >= 50"
CurrentDb.QueryDefs("MYTempQuery").sql = strSQL"

and I get the following error

Runtime error 3265
Item not found in this collection

I commented that statement and I proceed with the execution of the following statement

DoCmd.FindRecord strsearch, acAnywhere, False, acSearchAll, , acAll, False

I am getting the following error:

Runtime Error 2162
A macro set to one of the current fields properties failed beacuse of an error in a FindRecord action argument.

Please help

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Does MyTempQuery already exist?  If not, you'll need to create it.

Replace this line

CurrentDb.QueryDefs("MYTempQuery").sql = strSQL

with this:

CurrentDb.CreateQueryDef("MyTempQuery", strSQL)

When you're done, you can also delete it by calling

spacetravellerAuthor Commented:
Hi John, I am getting
 compile error
 Expected: =

OK, let's try something else.  Create a new query.  Leave it blank and save it as "MYTempQuery"

Then, try running your original code.  (Don't use my CreateQueryDef line.)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spacetravellerAuthor Commented:
It worked!!! Thanks. But, I want to create and delete Queries at run time. Is there a solution for that.

Thanks A lot.
Sorry I was never able to get back to you spacetraveller; I've been under the weather lately.  Feel free to open a new question to give someone else a chance to explain creating and deleting queries at run time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.