Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a control in an SQL criteria statment??

Status
Not open for further replies.

JennyPeters

Programmer
Oct 29, 2001
228
US
I'm working on an Access .adp and am making an SQL statment query (not a stored procedure) that needs to reference a control on the form. Of course the good old 'builder' no longer seems to exist to help.

In the criteria column, I have entered:
= Forms![NewProducts]![CategoryID]

...which gives me an error stating "Invalid or missing expression".

Can you not reference a control in an Access .adp query?

Thanks,

jenny
 
Have you tried passing the value of the control to a global var. and then pass the value of the global to a function. You can then use the function in the crit.
 
You can either:

Create your view (as we are working on MSDE/SQL - Access would call it a Query) without the criteria, but then open the query with a criteria e.g. "SELECT * FROM qryMyQuery WHERE CategoryID=" & Forms("NewProducts").[CategoryID] (that is adding the current value as a literal to the SQL statement). This will mean dragging all of the matching records to the client then filtering them client-side.

Create a parameterized view - see "Using parameters in the SQL statement of a form or report" in the help. This will only return the records we want (more efficient, as filtered server-side), but is a little more awkward to use.
 
Just get rid of the "=" in the criteria box. That's already assumed.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top