Help with using the "OR" in Criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Query and in two of my fields I have criteria. In the ID field I
have [Forms]![frm_Machine]![cbo_MachineNum]. In the Date field I have on the
next line of criteria (OR) Between [Forms]![frm_DateRange]![txtStartdate] And
[Forms]![frm_DateRange]![txtEndDate]. My thought was since they are on
different lines in the criteria that I would on either have to get the
Machine Number from the one form when I open my query or enter just the date
range. But it always prompts me for both. Is there another way I can get it
to work where I can choose either by Machine Number or Date Range?

Thanks
 
I have a Query and in two of my fields I have criteria. In the ID field I
have [Forms]![frm_Machine]![cbo_MachineNum]. In the Date field I have on the
next line of criteria (OR) Between [Forms]![frm_DateRange]![txtStartdate] And
[Forms]![frm_DateRange]![txtEndDate]. My thought was since they are on
different lines in the criteria that I would on either have to get the
Machine Number from the one form when I open my query or enter just the date
range. But it always prompts me for both. Is there another way I can get it
to work where I can choose either by Machine Number or Date Range?

Thanks

I'd suggest putting both criteria on *one* form; the form should be
unbound, and the textbox or combo box MUST be unbound. Note that the
query will *not* open the form for you; you must open the form FIRST,
then enter the criteria, then open the query.

It's convenient to base a Form (for onscreen viewing) or a Report (for
printing) on the query, and put a command button on the criteria form
to open that object. The user should generally not be required to see
the query window or the query datasheet at all.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
the OR keyword doesn't work like that. in only works in
one criteria such as start data or end date.
you will need two(2) queries for this, one for the by
machine and the one for by date.
i don't know how you are triggering the query so i am
guessing a button.
so behind your button you would need to put code like this:
if isnull(cbo_machinenum) then
docmd.openquery "bydatequery", acnormal
else
docmd.openquery "bymachinequery", acnormal
end if
it is dificult to have 1 all incompussing query to cover
all the different criterias. as a rule the more varied
criteria you have the more querries you will need. it can
be done but requires heavy duty code and usually done with
SQL.
-----Original Message-----
I have a Query and in two of my fields I have criteria. In the ID field I
have [Forms]![frm_Machine]![cbo_MachineNum]. In the Date field I have on the
next line of criteria (OR) Between [Forms]!
[frm_DateRange]![txtStartdate] And
[Forms]![frm_DateRange]![txtEndDate]. My thought was since they are on
different lines in the criteria that I would on either have to get the
Machine Number from the one form when I open my query or enter just the date
range. But it always prompts me for both. Is there another way I can get it
to work where I can choose either by Machine Number or Date Range?

Thanks
.
 
Back
Top