error 91 object variable or with block variable not set

Hi I am getting the above error on a VNA statement, when trying to set the SQL definition of a query on ms/access.
Can anyone help?

João serras-pereiraAsked:
Who is Participating?
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.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Try the follwing:
dim qdf as querydef
set qdf=currentdb.querydefs("q02_ExameDef")

Open in new window

Gustav BrockCIOCommented:
You need something like this:

Set q02_ExameDef = CurrentDb.QueryDefs("q02_ExameDef")  ' Name of query.
q02_ExameDef.SQL = strSetSQL
Set q02_ExameSet = q02_ExameDef.OpenRecordset()

Open in new window

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
Don't you have to save the querydef before you open it?
João serras-pereiraAuthor Commented:
Hi !
Thanks a lot! I was copying an old code and forgot to do it completely. So started scratching my head on it. THANKS!!!

I am awarding a bit more points to Gustav as  he took the care to actually sample with my variable bnames
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.