Parameter queries - mdb can't find the name ... you entered into the expression

  • Thread starter Bill Reed via AccessMonster.com
  • Start date
B

Bill Reed via AccessMonster.com

I took a long time to find this info, so I thought I would post it for the
next guy.
The problem arises from using the widely distributed code below:

Set db = CurrentDb
Set qdf = db.QueryDefs(strQueryName)

For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm

This works great for criteria in queries that reference fields on open
forms. I don't know how one would deal with closed forms, but that's a
subject for another post.
My problem was that the parameters I was looking for needed to be provided
by a prompt in the query, such as "[Enter ID # here]". I kept getting the
error msg in the subject line of this post. I finally found the answer in a
post in this forum. My apologies to it's author for not copying down
his/her name. Anyway the problem was solved by using an input box as in the
following code:

Set db = CurrentDb
Set qdf = db.QueryDefs(strQueryName)
For Each prm In qdf.Parameters
prm.Value = InputBox(prm.Name)
Next prm
Set rs = qdf.OpenRecordset 'dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top