Solved

Identify match in two tables

Posted on 2014-12-04
7
133 Views
Last Modified: 2014-12-04
I have two tables.  In one of them there is a field named "Property ID".  In the other one there is a field named "Account No".   Both field are text fields.

Also I have a form bound to the 1st table.  If there is a matching value in the 2nd table ("Property ID" = "Account ID") then I want a label to appear on the form indicating that there is a match.

How can I do this?
0
Comment
Question by:SteveL13
  • 4
  • 2
7 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40480699
Change "I have a form bound to the 1st table" to "I have a form bound on a query based on the 1st table", and that query can be:

SELECT Table1.*, IIf(IsNull([Table2].[Account Number]),"","Match") AS MyLabel
FROM Table1 LEFT JOIN Table2 ON Table1.PropertyID = Table2.[Account Number];

Open in new window

0
 

Author Comment

by:SteveL13
ID: 40480717
Where do I put this code?  I tried in the on current event of the form but that doesn't work.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40480736
In the "Record Source".

You will need to modify Table1 and Table2 names. MyLabel is the new field which will say "Match" if there is a match, and nothing if there isn't.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:SteveL13
ID: 40480749
But the record source of the form is a table.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40480779
That's why I said:

Change "I have a form bound to the 1st table" to "I have a form bound on a query based on the 1st table"

It's simplest to add another column to the 1st table.
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40480808
If for some reason you don't want to change the RecordSource, then add a Text Box and use this as the Control Source of the Text Box:

=IIf(DCount("[Account Number]","Table2","[Account Number] = """ & [PropertyID] & """")>0,"Match","")
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40480852
As an aside - the recordsources for forms and reports should almost always be queries.  That allows you to:
1. Limit the rows/columns fetched from the database by using a where clause
2. Avoid the use of domain functions to "look up" values
3. Provide a permanent sort order for the recordset so rows are ordered in a predictable sequence
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question