parameters from form don't work

C

cporter

This query works:

SELECT WORKORD.DAYDOWN, WORKORD.DAYUP, WORKORD.TIMEDOWN,
WORKORD.TIMEUP, WORKORD.MACHID, WORKORD.EMPLOYEE, WORKORD.ACTION,
WORKORD.REQUEST1, WORKORD.COMMENT1, WORKORD.COMMENT2, WORKORD.WONO,
WORKORD.THD, WORKORD.SUBSYS
FROM WORKORD
WHERE (((WORKORD.MACHID)=[Enter Machine ID]));




This one doesn't and I don't know why:

SELECT WORKORD.DAYDOWN, WORKORD.DAYUP, WORKORD.TIMEDOWN,
WORKORD.TIMEUP, WORKORD.MACHID, WORKORD.EMPLOYEE, WORKORD.ACTION,
WORKORD.REQUEST1, WORKORD.COMMENT1, WORKORD.COMMENT2, WORKORD.WONO,
WORKORD.THD, WORKORD.SUBSYS
FROM WORKORD
WHERE (((WORKORD.MACHID)=[Forms]![frmDate_MachId]![MachID]));
 
J

Jerry Whittle

By "doesn't" work, what do you mean? Error message? No records? Too many
records?

Make sure that everything is spelled right in:
[Forms]![frmDate_MachId]![MachID]

The frmDate_MachId form must be open. It can be invisible but needs to be
open.

Is MachID a text box or something like a list or combo box?
Is MachID bound to a table or unbound?
 
M

Michel Walsh

Hi,


The syntax FORMS!FormName!ControlName works only with DoCmd; DXXX()
functions, like DCOUNT, DMAX, ...; as RowSource for a list or combo box; and
in similar context,

but does not work with CurrentDb. See
http://www.mvps.org/access/queries/qry0013.htm


If you have to use the object CurrentDb, you have to resolve the parameter
with your VBA code, like:

================
Dim qdf As QueryDef : qdf=CurrentDb.QueryDefs("myQuery")
Dim param As DAO.Parameter
for each param in qdf.Params
param.Value = eval(param.Name)
next param

Dim rst AS DAO.Recorset
set rst=qdf.OpenRecorset( ...options...)
================


where the line

param.Value=eval(param.Name)


assumes that EACH parameter is of the form FORMS!FormName!ControlName, or
is a name that leads to EVALuation through the function eval() applied to
its name. That assumption can hardly hold in general, no need to say.



Hoping it may help,
Vanderghast, Access MVP
 

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