Solved

Compare Tables MS Access 2007

Posted on 2012-03-21
10
352 Views
Last Modified: 2012-04-02
Good Afternoon All,

I have two tables in an access database.  The first table is tblCAD and the second table is tblPCR.  I am trying to compare the field in tblCAD.IncNum to tblPCR eIncNum.  The data is coming from a website.  TblCAD represents CAD dispatches from our local 9-1-1 center.  TblPCR is coming from a second website for patient care reports.  Each is stored in a seperate table in access.  The common field is IncNum.  The CAD data comes down with an incident number attached.  As the EMT completes the report he also enters the incident number as eIncNum in the tblPCR table.  I want to compare the two incident numbers.  If the incident number is in tblPCR matches the incident number in tblCAD then I know the report was completed by the EMS provider.  

I do not know if it is possible but I would also like to see the Incident Numbers in tblCAD that have no match in tblPCR.  I want to see both completed reports and uncompleted reports.  

the CAD incident number comes down as 2012-85.  The employee may or may not use the 2012.  There report may show an incident number of 85 or 2012-85.  So I am looking for this to pick up either match.  

Any help would be greatly appreciated,

Lisa
0
Comment
Question by:AnneYourPointIs
[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
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:colonytire
ID: 37749045
You should be able to use Right(tablefield, 3) in your query so it uses the last 3 characters ie your example "-85" would be returned.  Info on the query can be found here:
http://office.microsoft.com/en-us/access-help/compare-two-tables-and-find-records-without-matches-HA010205132.aspx
0
 

Author Comment

by:AnneYourPointIs
ID: 37749159
I have tried this and it is not working for me.  It produces a query full of bad data.  The information in tblCAD does not match the information in tblPCR.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37749506
AnneYourPointIs,
<see the Incident Numbers in tblCAD that have no match in tblPCR.>

Try the "unmatched" query wizard in Access:
Create-->Query Wizard-->Find Unmatched....
0
Technology Partners: 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!

 
LVL 5

Expert Comment

by:DoveTails
ID: 37749827
I obtained a query similar to the following from the EE site in the past.
I modified it to match your table names (and included an ID field):
Data in tblCAD that have no records in tblPCR:
 
SELECT tblCAD.ID, tblCAD.incnum
FROM tblCAD
LEFT JOIN tblPCR ON tblCAD.incnum = tblPCR.eIncNum
WHERE (tblPCR.eIncNum) Is Null;
================================
adding the NOT keyword shows data in tblCAD with matching records in tblPCR

SELECT tblCAD.ID, tblCAD.incnum
FROM tblCAD
LEFT JOIN tblPCR ON tblCAD.incnum = tblPCR.eIncNum
WHERE (tblPCR.eIncNum) Is Not Null;
===================================

To remove the year from your Inc number, you may have to build a query to Trim that value away.  Here's an example:

WithoutYear: Trim(Right([incNum],Len([IncNum])-InStr([IncNum],"-")))
0
 

Author Comment

by:AnneYourPointIs
ID: 37752262
I created two queries and applied your suggestion of Trim(right(.  I applied the two new queries to your suggestion above replacing the queries for the tables.  I get a data type mismatch.  It works fine for the tables but trimming the incident numbers down so they match on both sides and then running the query is where I get the error.  Here is what I have:

SELECT qryCADTrimIncNum.cadID, qryCADTrimIncNum.NewCADIncNum, qryCADTrimIncNum.Unit, qryPCRTrimIncNum.eCompany, qryCADTrimIncNum.IncDate
FROM qryCADTrimIncNum LEFT JOIN qryPCRTrimIncNum ON qryCADTrimIncNum.NewCADIncNum = qryPCRTrimIncNum.NewPCRincNum
WHERE (((qryPCRTrimIncNum.NewPCRincNum) Is Null));
0
 
LVL 5

Accepted Solution

by:
DoveTails earned 500 total points
ID: 37753315
AnneYourPointIs,
I see what you're talking about.  I usually try to use the JOIN syntax as opposed to the NOT IN syntax because it's more efficienct. However, in this case, it may be worth considering using the NOT IN.

Here's an example (directly on the tables and by-passing the underlying queries)

SELECT * FROM tblCAD
WHERE Trim(Right([incNum],Len([IncNum])-InStr([IncNum],"-"))) NOT IN (SELECT Trim(Right([eIncNum],Len([eIncNum])-InStr([eIncNum],"-"))) FROM tblPCR);
0
 
LVL 5

Expert Comment

by:DoveTails
ID: 37753403
An additional point ....   I'm assuming your 'mismatch' error message is due to data existing in one table and not in the other, yet that's what you hoping to accomplish.  So using different syntax seems to be the way to go.

 Someone else here on EE with a greater understanding may be able to clarify, but that's the only reason I can see for the error.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37753850
^
correct.

AnneYourPointIs,

Perhaps if you posted a sample of the database that exhibits this issue, it would be easier...
0
 

Author Comment

by:AnneYourPointIs
ID: 37797849
Ok Dove,

You have put me on the right track, and it appears that the below query is offering the data that I was looking for.  Thanks for your help!

SELECT tblCAD1.CADID, tblCAD1.IncDate, tblCAD1.CADIncNum, tblPCR1.ePCRNum, tblCAD1.IncAddress, tblCAD1.Unit, tblPCR1.eCompany, tblCAD1.Response, tblCAD1.PSAP, tblCAD1.Disp, tblCAD1.Enr, tblCAD1.Arr, tblCAD1.EnrHosp, tblCAD1.ArrHosp, tblCAD1.Clear
FROM tblCAD1 LEFT JOIN tblPCR1 ON tblCAD1.CADIncNum = tblPCR1.PCRIncNum
WHERE (((tblCAD1.IncDate)>=#2/1/2012#) AND (Not (tblCAD1.ArrHosp) Is Null));
0
 
LVL 5

Expert Comment

by:DoveTails
ID: 37797939
Excellent,

Cheers
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

705 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