Solved

Identify match in two tables

Posted on 2014-12-04
7
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 37

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

732 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