Parameter Queries

M

Meilu

Hello,

I have a general question.
Below is a Query I wrote which uses a Form field as it's
parameter:

Query is called: qryClientContact

SELECT tblContact.EntityName, tblContact.ContactName,
tblContact.EntityType
FROM tblContact
WHERE (((tblContact.EntityName)=[Forms]![frmClientPO]!
[Client Name]) AND ((tblContact.EntityType)='Client'));

This query works fine on its own. But here's the problem.

I try to use it after clicking a button on the Form:
frmClientPO

This is the code I use to try to open the query.
Dim strQry As String
Dim cInfo As String

strQry = "qryClientContact"

Set db = CurrentDb()
Set rec = db.OpenRecordset(strQry)

But the error I get is:
Too few parameters, 2 expected.

I know it has something to do with using the Form fields
as parameters... but I don't know how to get around it?

Any ideas?
Meilu
 
P

Petrucci2000

Hi,

My name is Eric. Thank you for using the Microsoft Access Newsgroups.

You wrote:
"..the error I get is: Too few parameters, 2 expected.."

when running the following code against Parameter Query

Dim strQry As String
Dim cInfo As String

strQry = "qryClientContact"

Set db = CurrentDb()
Set rec = db.OpenRecordset(strQry)


SOLUTION:
==================
Rewrite your code as follows

Dim rec As DAO.Recordset
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("qryClientContact")

qdf![Forms]![frmClientPO]![Client Name] = "Some Client Name"

Set rec = qdf.OpenRecordset()



I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."
 

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