473,411 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

List query

Need help setting a select query where person enters a list of zipcodes
to lookup. I want to prompt the user to enter all the zip codes, then
run the query against to table to pull all records. Thanks.

May 22 '06 #1
2 1385
This example assumes the person enters the zip codes into a text box,
separating them with spaces. You set the AfterUpate property of the text
box to [Event Procedure]. In this event, you save any edits that are in
process, parse the zip codes into an array, and build that into a string to
use as the Filter of the form. The field to be filtered is a Text type
field, named Zip. If the user entered no zip codes, you show all records.

Private Sub txtZipList_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varZips As Variant 'Array of zip codes
Dim i As Integer
Dim lngLen As Long

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If

If Not IsNull(Me.txtZipList) Then 'Show all if blank.
varZips = Split(Me.txtZipList, " ")
'Build up the Where string from the array.
For i = LBound(varZips) To UBound(varZips)
strWord = Trim$(varZips(i))
If strWord <> vbNullString Then
strWhere = strWhere & """" & strWord & """, "
End If
Next
'Remove trailing comma and space, and use IN.
lngLen = Len(strWhere) - 2
If lngLen > 0 Then
strWhere = "[Zip] IN (" & Left(strWhere, lngLen) & ")"
End If
End If

'Apply the filter.
If strWhere <> vbNullString Then
Me.Filter = strWhere
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<fo*******@martecgroup.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Need help setting a select query where person enters a list of zipcodes
to lookup. I want to prompt the user to enter all the zip codes, then
run the query against to table to pull all records. Thanks.

May 22 '06 #2
fo*******@martecgroup.com wrote in
news:11**********************@i40g2000cwc.googlegr oups.com:
Need help setting a select query where person enters a list of
zipcodes to lookup. I want to prompt the user to enter all
the zip codes, then run the query against to table to pull all
records. Thanks.

To have the query prompt:
SELECT * from ZipCodes WHERE zipcode IN ([Enter zipcodes with comma
between])

To get the list from a textbox:
SELECT * from ZipCodes WHERE zipcode IN ([Forms!myform!txtZiplist])
--
Bob Quintal

PA is y I've altered my email address.
May 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lastusernameleft | last post by:
Is there a .NET method for doing this? I haven't found anything else that works. Thanks
4
by: MSD | last post by:
I am running a report that uses a query as its record source and opens a form collecting beginning and ending item numbers to feed to the query. This works, but now I'm trying to use the result of...
2
by: ormy28 | last post by:
I really need some help with the following problem if anyone would be willing. I need a list box to list the opposite of what appears in a query. Heres the details: My database is for a...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
1
by: Stephene | last post by:
New to the world of web design/php/mysql and need help please. What I'm trying to do: I would like a web page with three drop down menus each populated by a query The first represents...
3
by: rhobson2 | last post by:
Hello, I wrote a database applicaiton using Access XP (2002) and everything has been working good for the client until they purchased a couple of new computers with Access 2003. The meetings...
5
by: JvC | last post by:
Background Access 2003. MDB Front End. I am populating a list box with the names of queries in the system. I am searching for strings in the query names and then creating a value list for users...
0
by: c0mrade | last post by:
I have a problem with getting the list items, below is my hibernate code, after that code there is my method ..and below that is my junit test. How can I make sure that query is executing properly,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.