trouble running query with string as criteria

J

Jeff Klein

I have a query that has [Date] in the criteria. When I run the query by
itself it asks me to enter the [Date]. this works great although I want to
run this query from a form. On the form I have a text box that I type in
the date and when I click the command button the date in the text box will
set str_date = text1.value and show the query. I thought I could replace
the [Date] in the query with [str_date] but it still asks me to enter the
str_Date. (I have str_Date as Public) How do I get the value in the text
box to run in the query?
 
J

Jeff Conrad

You may be making this much more difficult than need be.

In the query, replace [Date] on the criteria line of the date column with
something like this:

[Forms]![NameOfYourFormHere]![text1]

Adjust to your actual form and control name.

As long as the form is open when you run the query, it will look for that
text box holding the date value and you will not get any prompts to provide
a date. You may also want to first check to see whether the user actually
entered a date in the text box before running the query.

Side Note: If one of your table fields is actually called "Date" you may
want to consider renaming it to something like TaskDate, ScheduleDate, etc.
Date is a reserved word in Access and it may get confused from time to time
about whether you are referring to a table field or a built-in function.
 

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