error on SQL select clause...

B

Brad Pears

I have some code that sets a recordset variable and then looks at the
..recordcount property for the recordset in the 'apply filter' event on an
access form. I am doing this to determine the number of records returned
from the filter criteria the user has just selected. Usinmg this method I
can tell the user if no records were found.

For some reason, I am getting the error 'Too few parameters - expected 1'
when I try to set this recordset - but only when the user uses the
right-click mouse button to activate the menu where they can enter a filter
value when on a particular field. When they use the 'filter by form'
function, this error does not occur.

The SQL clause is set and appears as follows...

' Use the filter() clause to set the SQL clause to whatever the user has
selected
dim strSQL as string
strSQL = "select * from Customers where " & filter()
' Now set the recordset
set RS = currentdb.openrecordset(strSQL)

' When I view the contents of the SQL clause at this point, it looks like
this...

"select * from Customers where
((frmCustomerInput_v4.PrimarySalesperson="Brad Pears"))

As soon as I execute the statement, the following error occurs...

"Too few parameters. Expected 1."

If I then remove the "frmCustomerInput_V4." in front of 'PrimarySalesperson'
(using the immediate debug window) so the SQL clause looks like this...
"select * from customers where ((PrimarySalesperson = "Brad Pears"))" it
works fine! - which leads me to believe that for some reason when you use
the right-click on a fowm field to enter filter criteria for that field,
ACCESS can no longer see any controls on the form you were on when you right
click to get the menu...

The problem is that this SQl statement is being built automatically and uses
the filter() keyword - so I cannot remove the form name qualifier.

I know this is confusing. Has anyone had this problem before? If so, how
did you fix it if you did...

Thanks,

Brad
 
B

Bob

Your Where clause has to refer to a field in the table Customers. What is
the name of that field? I suspect it is PrimarySalesperson and not
frmCustomerInput_v4.PrimarySalesperson.

Bob
 

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