473,396 Members | 2,004 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,396 software developers and data experts.

How do I return search results for a field with multiple values?

I'm using Access 2002.

I have a query field set up that references a form, Policy_File_Inventory, that has an unbound field, BarcodeNumber.

The form has several options related to the BarcodeNumber field. I am interested in what happens when the fourth option is selected. (The first and second selections work fine as is. The third option just displays all records.)

Expand|Select|Wrap|Line Numbers
  1. IIf([Forms]![Policy_File_Inventory]![Frame4]=1,[BoxBarcode] Is Null,
  2. IIf([Forms]![Policy_File_Inventory]![Frame4]=2,[BoxBarcode]=[Forms]![Policy_File_Inventory]![BarcodeNumber],
  3. IIf([Forms]![Policy_File_Inventory]![Frame4]=4,[FileBarcode]=[Forms]![Policy_File_Inventory]![BarcodeNumber] OR [ChildBarcode]=[Forms]![Policy_File_Inventory]![BarcodeNumber],"")))
The code I currently have here returns the results I want when the FileBarcode or ChildBarcode equals what is input into the BarcodeNumber field. The problem is that, in some cases, the ChildBarcode field has multiple values.

Is there some way I can make the search work when searching for one value listed in the ChildBarcode field for a record that has multiple values in the ChildBarcode field?


Note: I didn't set up this code. I just copied and pasted from another similar query and changed the field names to work with my new query and form. I also added the bit with the "OR [ChildBarcode]..." to make the fourth option search the ChildBarcode field in addition to the FileBarcode field.
I'm trying to figure this out myself and it isn't going very well.
Feb 23 '12 #1
10 1631
NeoPa
32,556 Expert Mod 16PB
I'd love to help, but you don't explain the data structure of any tables you are probably using (You haven't explained that either).

Clearly you've put some effort into the question, but unfortunately left out some critical info, without which it's really hard to understand what you're trying to ask for.
Feb 24 '12 #2
I was trying not to write a book, and I'm not sure what exactly you need to know, but here's everything I know:

There's only one table in use here.
There's an AutoID, BoxBarcode, and FileBarcode for each record. Some records have a ChildBarcode. A few records have multiple barcodes separated by a comma and space in the ChildBarcode field.
I'm pretty sure the fields are text.

There's a query with the AutoID, BoxBarcode, FileBarcode, and ChildBarcode fields. The last field in the query has the code above.

There's a subform that has the BoxBarcode, FileBarcode, and ChildBarcode fields.

There's a form, Policy_File_Inventory, that has the [Frame 4] that has 4 options. The form also has the [BarcodeNumber] unbound field that users input data in. And the form displays the subform.

The first option is to enter new records. When this option is selected, no records initially appear in the subform. The user enters a BoxBarcode into the BarcodeNumber field in the form and the cursor moves to the FileBarcode field in the subform. As FileBarcodes are entered, new records are created, each with the same BoxBarcode.

The second option is to search the BoxBarcode field for any records matching the string entered in the BarcodeNumber field in the form.

The third option is to display all the records in the table.

The fourth option is to search the FileBarcode field or ChildBarcode field for any records matching the string entered in the BarcodeNumber field in the form.

As it is, if the ChildBarcode field for a record is "12345" and I enter "12345", it returns the record I want.
But if the ChildBarcode field for a record is "12345, 54321", I want to be able to pull up that record when I search for "12345" and when I search for "54321"... and I have no idea how to do that.
Feb 24 '12 #3
This was suggested as a replacement for the end of my code:
Expand|Select|Wrap|Line Numbers
  1. OR InStr([ChildBarcode],[Forms]![Policy_File_Inventory]![BarcodeNumber]),"")))
I am going to give it a try tomorrow morning.
Feb 24 '12 #4
NeoPa
32,556 Expert Mod 16PB
M3g4tr0n:
I was trying not to write a book, and I'm not sure what exactly you need to know
I sympathise with the idea, but your latest post (** Edit - Referring to post #3 **) is a pretty concise version of the basic data required. It seems you have a pretty good idea of what's needed after all, even if you didn't necessarily appreciate that at the time :-)

Your posted code is well displayed, but I assume it's in the WHERE clause of your SQL (as that bit's still not absolutely clear). On that assumption I'll suggest a replacement to handle your need (which is now very clear) :
Expand|Select|Wrap|Line Numbers
  1. CHOOSE([Forms]![Policy_File_Inventory]![Frame4],
  2.        ([BoxBarcode] Is Null),
  3.        ([BoxBarcode]=[Forms]![Policy_File_Inventory]![BarcodeNumber]),
  4.        (True),
  5.        (([FileBarcode]=[Forms]![Policy_File_Inventory]![BarcodeNumber])
  6.     OR ([ChildBarcode] Like '*' & [Forms]![Policy_File_Inventory]![BarcodeNumber] & '*')))
I've simplified your original somewhat, by using CHOOSE(), and used Like with wildcards for matching the [ChildBarcode].
Feb 24 '12 #5
NeoPa
32,556 Expert Mod 16PB
M3g4tr0n:
This was suggested as a replacement for the end of my code:
That could work, but is not a SQL-based approach. I wouldn't recommend it, especially as there is a more appropriate approach available (See post #5).

PS. We cross-posted so I didn't see yours until after I'd submitted mine.
Feb 24 '12 #6
No SQL as far as I know.

The code I posted is in the Field row of the last column of my query.
Feb 24 '12 #7
NeoPa
32,556 Expert Mod 16PB
M3g4tr0n:
No SQL as far as I know.
Understandable, but it is all based on SQL. See Extracting/Updating SQL from a QueryDef.

You can put the SQL I posted in post #5 in that field in your query and it should work. I guess you simply have True in the Criteria row. That makes sense.
Feb 24 '12 #8
I tried the non-SQL yesterday morning and it worked.

I didn't have the chance to try the SQL. I will give that a try Monday morning.
This won't be going into production until Tuesday, so I still have a chance to see what works best.

I will report back then and choose the best answer.
Feb 25 '12 #9
I guess you simply have True in the Criteria row.
The criteria is actually <>False which I don't quite understand, but it works like that. And I suppose now is a good time to figure out what it means.
Feb 25 '12 #10
NeoPa
32,556 Expert Mod 16PB
Ha! That makes sense. I didn't realise Access was that clever.

I'll explain why, but many, many people don't get Booleans so don't worry if you don't either.

Any value that is not zero will trigger a true branch. Tests are done in various places and ways and, fundamentally, they all come down to :
Expand|Select|Wrap|Line Numbers
  1. IF <Boolean> THEN <TrueOption> ELSE <FalseOption>
  1. As Booleans are stored as integers, it's possible for any value valid integer value to be treated as a Boolean.
  2. True = -1 (all 1s in binary) and False = 0 (all 0s in binary).
This leaves the question of values which are neither. These are treated as triggering the <TrueOption> when tested, yet are actually equal to neither True nor False. How, then, to test them in SQL if you must compare them with something (as this is all the Query grid allows)? The answer is to ensure they are not False, or :
Expand|Select|Wrap|Line Numbers
  1. <>False
Feb 26 '12 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gabriel Cooper | last post by:
Usually when I access db search results it's something like this: cursor.execute("select A1,A2,A3,A4 from B where C") for (a1,a2,a3,a4) in cursor.fetchall(): stuff() But sometimes the point...
4
by: dave | last post by:
I am wondering if the following can be done. I want to setup a search page that utilizes full text searching in sql2000. I want the user to type in say "where is bill" and have the query search...
10
by: Craig Keightley | last post by:
I have the following array: function showCPUs(){ //name brandID dualCore dualProcessor var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=;
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
2
by: Rosanne Rohana | last post by:
I'm trying for return user info (first name, last name, etc.) from a Netscape 4.16 LDAP server using the System.DirectoryServices. I'm able to get authenticated successfully, but when I attempt to...
8
by: Chris A via AccessMonster.com | last post by:
I have an interesting problem that I have yet to come accross that I can't change data structure on because it is an export from filemaker I am reformatting for another dept. anyway. I have a table...
4
by: PI | last post by:
Hi guys, I'm struggling with this much longer than I think I need to, I guess you could help me here: How do I make the results of a search display on the same page as the search, sort of beneath...
3
by: cssExp | last post by:
Here in a form i have the following. note: the following is a result of dynamic html element creation. <input type="hidden" name="category" value="science" /> <input type="hidden"...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
5
by: darkestknight43 | last post by:
Hello, I've been working on this piece of code for quite a while. Essentially it is a Search Tool which pulls Mobile Home information from a database and displays listings based on the users input....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.