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

Search on Multiple tables

Split from thread:
http://bytes.com/topic/access/answer...do#post3790250

1 - How do I search more than one table in a keyword search? (I know I need a join or a UNION but I'm not sure how to implement it)

Essentially I have this code to search a set of tables:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch1_Click()
  2.    On Error GoTo problem
  3.    Dim strsearch As String
  4.    Dim strText As String
  5. '
  6.    strText = Me.TxtSearch1.Value
  7.    strsearch = "SELECT * " & _
  8.       "FROM [tblCompany] " & _
  9.       "WHERE (([Company_name] LIKE ""*" & _
  10.          strText & "*"") OR(Quote_Type LIKE ""*" & _
  11.          strText & "*""))"
  12.    Me.RecordSource = strsearch
  13. '  
  14. End Sub
  15.  

And I'm wondering how do I incorporate a UNION to add a second table to the search? The 2nd table I want to search is tblContact
Apr 21 '15 #1
4 1642
zmbd
5,501 Expert Mod 4TB
You may not need a union.
Without your table structure and relationships it will be difficult to provide any guidance.
-z
Apr 21 '15 #2
My table structure is relatively simple.

there are three tables - tblCompany, tblSupplier and tblContact.

tblSupplier contains five fields "Company_ID", "Contact_ID", Order, Price and ID. The first two fields are linked to tblContact and tblCompany.

tblCompany has 3 fields - ID, Company_Name, Quote_Type
tblContact has 7 fields - CompanyID, First_Name, Second Name, title, email, phone, address.

Connections
ID field in tblCompany is connected to Company_ID in tblSupplier

Company_ID field in tblContact is connected to Contact_ID in tblSupplier
Apr 21 '15 #3
I have attached an image of the relationships here

Attached Images
File Type: jpg relationships_supplier.jpg (18.7 KB, 288 views)
Apr 21 '15 #4
zmbd
5,501 Expert Mod 4TB
To be totally honest with you here, reading all of the threads, looking at what you have here... I'm Guessing at what you are actually after.

So from what it looks like to me, how I would handle this would be:
Two combboxes
One with recordsource to your tblCompany
One with recordsource to your tblContacts

Both CboBox set to show friendly name and return the primary key.
Now use the values of the the CboBoxes to search against tblSupplier building your string as needed... something along the filtering and cascade-CboBox articles:
Apr 21 '15 #5

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

Similar topics

4
by: Gobi | last post by:
Hello, I have a Database with lists of Clients in each. Every year a new tables is created with the naming convention "CloseYear" ie close1999, close2000 There are tables from this year back to...
1
by: Brian | last post by:
I'm trying to find a way to search multiple tables for the same record. Say I have 3 tables all with a name column, I need to search all 3 tables and find matching names. Is there an easy way to...
3
by: Katrina | last post by:
I am trying to write a piece of code that will search through a number of different tables (current one being tableNm) to look for a specific street name that has been entered by the user and saved...
0
by: SamKhazary | last post by:
I have created a database that has a main table with a description of different products. I have 5 other data bases that are linked sheets that have returns for the 5 different prduct groups. I'd...
3
by: divina11 | last post by:
How do I go through Multiple tables (tables 1-20) to search for a particular word e.g. "first" and then print the results (i.e. table name & column name which contains the word "first"). Not sure...
0
by: redpears007 | last post by:
Morning all! :) I have a database with multiple linked tables. I have created a search form with one txt box, for entering search criteria, and a listbox for each of the tables to isplay the...
2
by: deiv82 | last post by:
Hello everyone, I'm trying to do a little search engine for my website. Like often, I've the problem to operate on multiple tables. This is the part of code that interests my problem. It works...
1
by: Lyn DeMaio | last post by:
I've been tasked with taking two unrealted tables (Providers and Patients, no common field) and allow users, on one form (or form/subform) to search multiple fields in each table, select a record...
1
by: meisjen86 | last post by:
Hey guys, I'm working on a project from school. I want to be able to search for a term across multiple tables in a database. For ex. I have two tables(table a, table b) set up the exact same...
2
by: SKumar365 | last post by:
Hi, I have a database with multiple tables,( Tables are payroll data named as Jan'11, Feb'11 etc up to Dec'11). I would like to have a combo box in the form to show these tables, and a text box to...
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?
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:
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...
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
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...

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.