A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filter for Same Value in Two Fields



 
 
Thread Tools Display Modes
  #1  
Old November 27th, 2009, 06:08 PM posted to microsoft.public.access.queries
Dave
external usenet poster
 
Posts: 2,331
Default Filter for Same Value in Two Fields

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.
  #2  
Old November 27th, 2009, 06:44 PM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default Filter for Same Value in Two Fields

You stated:
shipped "From" Denver and that show shipped "To" Denver
Technically this would mean both values were Denver which might not make
much sense if you expected the From and To to be different. Assuming you are
viewing your query in design view, you would type "Denver" under the From and
To columns. If you want Denver to be in both fields, then "Denver" should be
on the same line in the grid. If you want From "OR" To to be Denver, then
type Denver on the first line of the criteria under From and the second line
under To.

--
Duane Hookom
Microsoft Access MVP


"Dave" wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.

  #3  
Old November 27th, 2009, 07:13 PM posted to microsoft.public.access.queries
Dave
external usenet poster
 
Posts: 2,331
Default Filter for Same Value in Two Fields

Okay, let me clarify. I used the word 'and' in the English sense; not as a
Boolean algebra sentence. Second, your solution did not work. What I want to
do is generate a list of records that have Denver in the "From" field in
addition to records that have Denver in the "To" field. No records will
populate both the "To" and the "From" fields with the same city name.



"Duane Hookom" wrote:

You stated:
shipped "From" Denver and that show shipped "To" Denver
Technically this would mean both values were Denver which might not make
much sense if you expected the From and To to be different. Assuming you are
viewing your query in design view, you would type "Denver" under the From and
To columns. If you want Denver to be in both fields, then "Denver" should be
on the same line in the grid. If you want From "OR" To to be Denver, then
type Denver on the first line of the criteria under From and the second line
under To.

--
Duane Hookom
Microsoft Access MVP


"Dave" wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.

  #4  
Old November 27th, 2009, 07:42 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Filter for Same Value in Two Fields

On Fri, 27 Nov 2009 10:08:01 -0800, Dave
wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.


Use OR logic. Create a query based on the table, put "Denver" (or, better, a
parameter referencing a control on a form) under From, and the same criterion
under To, *on a different line on the query grid*.

This will retrieve the record if From is equal to "Denver", or if To is equal
to "Denver" (or, for that matter, if both are equal to "Denver").
--

John W. Vinson [MVP]
  #5  
Old November 27th, 2009, 08:52 PM posted to microsoft.public.access.queries
Dave
external usenet poster
 
Posts: 2,331
Default Filter for Same Value in Two Fields

Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.



"John W. Vinson" wrote:

On Fri, 27 Nov 2009 10:08:01 -0800, Dave
wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.


Use OR logic. Create a query based on the table, put "Denver" (or, better, a
parameter referencing a control on a form) under From, and the same criterion
under To, *on a different line on the query grid*.

This will retrieve the record if From is equal to "Denver", or if To is equal
to "Denver" (or, for that matter, if both are equal to "Denver").
--

John W. Vinson [MVP]
.

  #6  
Old November 27th, 2009, 09:37 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Filter for Same Value in Two Fields

Enter "Denver" on the first criteria line under the To field.
Enter "Denver" on the second criteria line under the From field.



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
Okay, let me clarify. I used the word 'and' in the English sense; not as a
Boolean algebra sentence. Second, your solution did not work. What I want to
do is generate a list of records that have Denver in the "From" field in
addition to records that have Denver in the "To" field. No records will
populate both the "To" and the "From" fields with the same city name.



"Duane Hookom" wrote:

You stated:
shipped "From" Denver and that show shipped "To" Denver
Technically this would mean both values were Denver which might not make
much sense if you expected the From and To to be different. Assuming you are
viewing your query in design view, you would type "Denver" under the From and
To columns. If you want Denver to be in both fields, then "Denver" should be
on the same line in the grid. If you want From "OR" To to be Denver, then
type Denver on the first line of the criteria under From and the second line
under To.

--
Duane Hookom
Microsoft Access MVP


"Dave" wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.

  #7  
Old November 27th, 2009, 09:41 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Filter for Same Value in Two Fields

Assumption: You have two fields (From and To) in the record and both From and
To have a value.

If that is true you should be able to do as noted in earlier replies.

You could use
Field: IIF([From] = "Denver" OR [To] = "Denver",True, False)
Criteria: True

That is doing it the hard way.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.



"John W. Vinson" wrote:

On Fri, 27 Nov 2009 10:08:01 -0800, Dave
wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.

Use OR logic. Create a query based on the table, put "Denver" (or, better, a
parameter referencing a control on a form) under From, and the same criterion
under To, *on a different line on the query grid*.

This will retrieve the record if From is equal to "Denver", or if To is equal
to "Denver" (or, for that matter, if both are equal to "Denver").
--

John W. Vinson [MVP]
.

  #8  
Old November 27th, 2009, 09:56 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Filter for Same Value in Two Fields

On Fri, 27 Nov 2009 12:52:01 -0800, Dave
wrote:

Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.


Please define "does not work" - in particular open the query in SQL view and
post the SQL here, and indicate what works and what doesn't work. Or, post the
relevant fieldnames of your table (From, To, and the fields that you want to
show, and any other fields to which you're applying criteria).

The OR logic *is the correct solution*, it does work correctly (if done
correctly), it does not require any IF or conditional logic.

--

John W. Vinson [MVP]
  #9  
Old November 27th, 2009, 10:50 PM posted to microsoft.public.access.queries
Dave
external usenet poster
 
Posts: 2,331
Default Filter for Same Value in Two Fields

Your initial reply did not show up until after my last post. Thank you, the
method you suggested in that post worked.

-Dave



"John Spencer" wrote:

Assumption: You have two fields (From and To) in the record and both From and
To have a value.

If that is true you should be able to do as noted in earlier replies.

You could use
Field: IIF([From] = "Denver" OR [To] = "Denver",True, False)
Criteria: True

That is doing it the hard way.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
Just puting Denver in the criteria sections does not work. I need to write an
If statement of some kind (ie- If "From" or "To" = Denver Then show). Or an
Iif statement (Iif ("From" or "To" = Denver, show, hide). How would I do
this? Thanks.



"John W. Vinson" wrote:

On Fri, 27 Nov 2009 10:08:01 -0800, Dave
wrote:

There are two fields in my query. "From" and "To". For sake of ease, let's
say both these fields are US Cities. How can I pull all the records that show
shipped "From" Denver and that show shipped "To" Denver? Thank you in advance.
Use OR logic. Create a query based on the table, put "Denver" (or, better, a
parameter referencing a control on a form) under From, and the same criterion
under To, *on a different line on the query grid*.

This will retrieve the record if From is equal to "Denver", or if To is equal
to "Denver" (or, for that matter, if both are equal to "Denver").
--

John W. Vinson [MVP]
.

.

  #10  
Old November 28th, 2009, 12:08 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Filter for Same Value in Two Fields

On Fri, 27 Nov 2009 14:50:01 -0800, Dave
wrote:

Your initial reply did not show up until after my last post. Thank you, the
method you suggested in that post worked.


And it is the method that I suggested in my response as well, which must have
been phrased confusingly... sorry about that, and glad that John Spencer's
good advice worked for you!
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:51 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.