Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query by part or all of zip code 2

Status
Not open for further replies.

Eprice

Technical User
Joined
May 6, 2003
Messages
209
Location
US
Hi,
I have a form where a user enters info to pull up a report based on the zip code. The user may enter the whole zip code, which is not a problem, but they also want to be able to enter the first 2, 3 or 4 digits to get all zip codes for a larger area. Example, they may enter 90 or 901 or 9015 or 90156. I need a way to query the table to get all records by what they enter. I know I can do this with a lot of if statements but there should be an easier way that I can't find. Thanks for any suggestions.
Lisa
 
The field is formatted as text so I could use a str function.
 
Use a LIKE statement e.g.
Code:
WHERE ZipCodeField LIKE [Forms]![YourForm]![YourTextBox] & "*"
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
How do I use that in the query grid criteria?
 
In the criteria cell of ZipCodeField:
Like [Forms]![YourForm]![YourTextBox] & '*'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In the criteria paste
Code:
ZipCodeField LIKE [Forms]![YourForm]![YourTextBox] & "*"
Then replace YourForm with the name of your form and YourTextBox with the name of the texbox the users are entering the ZipCodes into.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Well, it finally worked after I tabbed out of the field on my report. Thanks both of you.
Lisa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top