Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access 2016 Merge Tables

Posted on 2016-11-23
8
Medium Priority
?
115 Views
Last Modified: 2016-11-28
I am attempting to create a database that combines information from 2 sources.  One is a time keeping system, Table A.  The other is from a payroll system TableB.

I want to create a new table that uses all the data in Table A and and adds the SSN and ITemID from Table B.  Two fields in Tables have to match.  EmID from Table A has to match AIdent from Table B.  Also Worked Department from Table A has to match DeptName in TableB.

I have to match multiple fields because some employees will work in multiple departments in a single pay period.

I've tried using Dlookup and I can't seem to get the data to merge properly.  I keep getting hundreds of duplicate records.

I'm attaching a sample file with fake data that matches the structure of my real DB.  Didn't want to share anyone's SSN.
Sample.accdb
0
Comment
Question by:Mwvarner
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 41899661
Since you have duplicate people rows in TableB and no way to refine the joining of the two tables, you need to remove the duplicates from TableB.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 41899706
Duplicate removal query
DELETE TableB.*
FROM TableB 
WHERE TableB.ID <> (Select Min(B.ID) From TableB As B
WHere (TableB.FirstName = B.FirstName) AND (TableB.LastName = B.LastName))

Open in new window

0
 

Author Comment

by:Mwvarner
ID: 41899733
The rows in Table B aren't completely duplicates.  The departments and assignments are different.   I know DLookup can use multiple criteria I just can't work out the syntax.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 46

Expert Comment

by:aikimark
ID: 41899769
Unless you can state when one TableB row should be used and when a different TableB row should be used in the table-join operation we can't help you.  I don't see any other columns that help in this process.
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 41899902
We don't have enough information to resolve the problem but as has already been mentioned, you need to eliminate any duplicates.  In both tables, you will validly have multiple rows for a given employee so you should create queries to summarize or group the data to get down to a single row per employee per source.  Then you can join the queries and not end up with nonsense in the output. The problem is caused because neither table is an employee "master".  Both tables are transnational and by definition, will include multiple rows for each employee.

Before you can do any joining, you need to make the data types consistent.  So the department code should be EITHER numeric or text.  I'm going to suggest that it be text unless you know for certain that at the source, it will NEVER contain non-numeric characters and NEVER require leading zeros.  Fields like SSN are NOT NUMERIC.  They may contain only numbers at present but they are CODES and CODES are  always text unless you have a death wish.  SSN can have leading zeros so unless you want to end up with SSN's that are less than 9 characters, you MUST define SSN as text.  Same with Zip CODE if that field is contained in any of your import tables, especially if you might have employees with Canadian addresses.

Using DLookup() is not the correct way to solve this problem.  You shouldn't ever use domain functions in queries especially if there is an alternative and in this case there is.

PS, including ItemID (whatever that is) will prevent tableB from being summarized to one row per employee and once that happens, the joins will always produce nonsense so we are going to need to know more about your ultimate goal to advise further.
0
 
LVL 18

Accepted Solution

by:
John Tsioumpris earned 2000 total points
ID: 41900126
Take a look at my attachment --> FinalJoinedTable (query)
Sample.accdb
0
 

Author Closing Comment

by:Mwvarner
ID: 41904845
Great Job and I really appreciate the assist. I have posted a related question so maybe you can help with that one as well.

Thanks again.
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 41904855
Look very carefully at the sample output created by John.  It might not actually work the way you need it to but then you never did explain how the de dupe should work.
1

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

715 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