0

I've been using MS Access 2010 for a while now and I have big problem. I'll attach a dummy database here for reference. It's simple, three tables: 2 for data and 1 to act as a junction for a many-to-many relationship. I have one query that I would like to be able to enter values. Lets say I enter the following:

+-------------+-------------+
|    NameA    |    NameB    |
+-------------+-------------+
|    Frank    |    Bob      |    
|    Frank    |    Harry    |
|    Tom      |    Harry    |
+-------------+-------------+

The 2 data tables will end up with redundant entries. It's as if the query simply adds a new entry regardless of what is already in the tables. How do I fix this?

Thanks in advance.

Update: Per request here is the query code

SELECT Table1.NameA, Table2.NameB
FROM Table2 
INNER 
JOIN (Table1 INNER JOIN Table3 ON Table1.ID = Table3.IDA) 
ON Table2.ID = Table3.IDB;
6
  • Have you got an index? What is wrong with the entries you show?
    – Fionnuala
    Aug 22, 2012 at 18:51
  • Copy and paste the query text so we can see it without opening your accdb file. please! Aug 22, 2012 at 19:33
  • This query is a SELECT query, not an INSERT query. A select query will only return results, not add records. Are you trying to write a query that will return results without duplicates? Aug 22, 2012 at 19:53
  • I do not care how, but I want to be able to add records without duplicates. With what I have now (the SELECT query), it adds the records but ignores the fact that it is making duplicates. How would an INSERT query fix this problem?
    – qmckinsey
    Aug 22, 2012 at 20:00
  • If you have a unique index, it will not be possible to add duplicates.
    – Fionnuala
    Aug 22, 2012 at 20:05

3 Answers 3

1

I've found an answer here.

The key points are as follows:

  1. The builtin functionality provided to the query via DataSheet View is very simple. It only adds new records regardless of creating redundant entries.

  2. The desired functionality cannot be easily implemented on the Query/Table level. Hence I've implemented it on the Form/Report level. Personally, I could see no way in theory to implement it on the Query/Table level, but I'm certain there are VBA gurus out there who can do anything.

  3. Designers can use a Combo Box for each desired field in the many-to-many relationship. This gurantees no redundant entries. Then to add new entries VBA code has to be added to the "On Not In List" property of the Combo Box. See link above.

Hope this helps someone in the future. I know I was happy. Thanks for the help.

1
  • if this is the answer that solved your issue, then mark it as the answer.
    – Malachi
    Dec 13, 2012 at 21:45
0

sounds like the Example from w3schools.com when you do your inner join it grabs information from both tables where any column Matches. I assume that there are other columns in both Tables.

0

Typically, a cross-reference table would join Table1 and Table2 like:


SELECT Table1.Name1, Table2.Name2
FROM ((Table1 INNER JOIN TableRef ON Table1.ID1 = TableRef.ID1) INNER JOIN Table2 ON Table2.ID2 = TableRef.ID2)

Try:


SELECT DISTINCTROW Table1.Name1, Table2.Name2
FROM ((Table1 INNER JOIN TableRef ON Table1.ID1 = TableRef.ID1) INNER JOIN Table2 ON Table2.ID2 = TableRef.ID2)

4
  • The query I have above was created by Access using the query builder. I see that syntactically your code is different, but don't they perform equivalent queries? Granted I think yours is easier to read.
    – qmckinsey
    Aug 22, 2012 at 20:06
  • I'm not sure how you have a select query adding rows to your database. That is not at all clear. Select simply displays rows. Anyway, I just edited my answer to show how DISTINCTROW can be used to reduce the results of the select statement down to unique rows. Aug 22, 2012 at 20:35
  • MS Access 2010 provides abilities via the DataSheet View of the query, which allows users to enter records via the query, not simply view the results of the query.
    – qmckinsey
    Aug 24, 2012 at 18:58
  • Ahhh. In that case, yes, your answer above is correct. Never allow data entry directly via a query object. Unless you don't care at all about the existing data. Aug 24, 2012 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.