Referring to a field in a form

I'm trying to create a query in which I'm referring to a text field in a form, but I'm getting an error:

Microsoft Access database engine does not recognize 'forms!Stats!txtFromDT' as a valid field name or expression

Why is this happening?

SELECT *
FROM tblEmployee
WHERE [Date] between forms!frmStats!txtFromDT and forms!frmStats!txtThruDT and [WorkerID] = forms!frmStats!lstWorkID;

Open in new window

David LelièvreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
That should be correct....is it on a subform within a main form?  and the form is open when the query executes?

Also, you'll want to use the Parameters dialog in the query to indicate to Access that the control reference contains a date/time value.   If you don't do this, Access will guess at the data type and may get it wrong.

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David LelièvreAuthor Commented:
Right, the form wasn't open thanks! It was on the main form.
0
David LelièvreAuthor Commented:
Sorry about this, but just a quick question related to this..

I've made a crosstab from the query and I'm getting the error:

Microsoft Access database engine does not recognize 'forms!Stats!lstSelect' as a valid field name or expression

Do I also have to the Parameters Dialog for this? (It's a multi selection listbox)

Thanks.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You can't point to a multi-select list box.

Jim.
0
David LelièvreAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.