473,386 Members | 1,864 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,386 software developers and data experts.

Search button code for categories in a subtable

If you need to make a search to find customers in a group (or groups) and the groups are defined in a separate table with a intermediate join table, then this piece of code is for you. The customers table here is called "accounts". You will need to create a text box called "Arguments" and a button call cmdCategorySearch and enter searches like this:

+business +active -london

Which will find any customers that are business and active but not in London.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCategorySearch_Click()
  2. strArg1 = Me.Arguments
  3. x = 0
  4. strSQL = "SELECT * FROM accounts"
  5. If Len(strArg1) > 0 Then
  6.     strArg2 = Split(strArg1, " ")
  7.     For Each v In strArg2
  8.         If InStr(v, "+") Then
  9.             v = Mid(v, 2)
  10.             If x = 0 Then strSQL = strSQL & " WHERE ((" Else strSQL = strSQL & " And "
  11.             strSQL = strSQL & "(accounts.id) In (SELECT accounts.id from qryAccounts_Groups WHERE groups.Group like '*" & v & "*' ) "
  12.         Else
  13.             v = Mid(v, 2)
  14.             If x = 0 Then strSQL = strSQL & " WHERE ((" Else strSQL = strSQL & " And "
  15.             strSQL = strSQL & "(accounts.id) Not In (SELECT accounts.id from qryAccounts_Groups WHERE groups.Group like '*" & v & "*' ) "
  16.         End If
  17.         x = x + 1
  18.     Next
  19.     strSQL = strSQL & "))"
  20. End If
  21. strSQL = strSQL & " ORDER BY accounts.account_name;"
  22. 'InputBox strSQL, , strSQL
  23. Me.RecordSource = strSQL
  24. End Sub
May 21 '07 #1
1 1378
NeoPa
32,556 Expert Mod 16PB
I assume from the wording of your thread that you're not looking for an answer but are simply sharing your code / solution to a problem you've encountered?
Jun 2 '07 #2

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

Similar topics

14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
4
by: Captain Wonky | last post by:
As the subject says... I'm a database novice even though I've been trying to learn Access for years. I've 'almost finished' several databases but always get stumped on something - this time it's...
2
by: rcmail14872 | last post by:
I have a form that lists several different categories for labels. I made a form that will let the user add a new category. On the Form the user can type in the name for the new category, then I...
0
by: JoRo | last post by:
I am working on a project where I want a very user-friendly interface. I have a datagrid of categories that uses the EditCommandColumn to do in-line editing of the category name. On the page is...
3
by: Pieter | last post by:
Hi, I need some search system, that will return me the records with in indicator of probability. This is for a VB.NET 2005 application with a SQL Server 2000 DataBase. I have a table with...
4
by: grabit | last post by:
Hi peoples I have the following query to return search results. How can i stop this from returning results containg words or phrases like "Hi Team, please check latest news. Cheers Rach" when i...
1
by: grabit | last post by:
Hi Peoples i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error...
0
by: Eugene Anthony | last post by:
BlogListingAll.aspx ------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="user_BlogListingAll.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML...
5
by: nicehulk | last post by:
I'm doing a library for DVD-movies and I'm trying to figure out how to search different categories like director, title, actor etc. (which are all variables in a DVD-class). Previously I did like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.