Results 1 to 2 of 2
  1. #1
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107

    Append Query is Appending 3 copies of a record

    I am accessing a query through VBA and am having an odd response from an append query. I am appending a record to an ALERT table if there is either a non-existing employee name, a null ID, or a duplicate ID. I am doing this process through three individual append queries that are indicated below:

    Code:
    'Append New Employee to Alert Table
    
    StrSQL = "INSERT INTO Alerts ( PERIOD, [Id], [Transaction Source], Yes, [Hold], " & _
    "[Name], Project, Task, [Type], [Date], [Employee Name], Quantity, [Rate], " & _
    "UOM, [Cost], [field 17], [Amount], Comment, Field19, Bill, Alert ) SELECT " & _
    "Temp.PERIOD, Temp.[Id], Temp.[Transaction Source], Temp.Yes, Temp.Hold, " & _
    "Temp.[Name], Temp.Project, Temp.Task, Temp.[Type], Temp.[Date], " & _
    "Temp.[Employee Name], Temp.Quantity, Temp.[Rate], Temp.UOM, Temp.[Cost], " & _
    "Temp.[17], Temp.[Amount], Temp.Comment, Temp.Empty, Temp.Bill, 'New Name' AS [Alert] " & _
    "FROM Temp LEFT JOIN NameCard ON Temp.[Employee Name] = NameCard.Name WHERE (((NameCard.Name) Is Null));"
    Code:
    'Append Duplicate ID to Alert Table
    
    StrSQL = "INSERT INTO Alerts ( PERIOD, [Id], [Transaction Source], Yes, [Hold], " & _
    "[Name], Project, Task, [Type], [Date], [Employee Name], Quantity, [Rate], " & _
    "UOM, [Cost], [field 17], [Amount], Comment, Field19, Bill, Alert ) SELECT " & _
    "Temp.PERIOD, Temp.[Id], Temp.[Transaction Source], Temp.Yes, Temp.Hold, " & _
    "Temp.[Name], Temp.Project, Temp.Task, Temp.[Type], Temp.[Date], " & _
    "Temp.[Employee Name], Temp.Quantity, Temp.[Rate], Temp.UOM, Temp.[Cost], " & _
    "Temp.[17], Temp.[Amount], Temp.Comment, Temp.Empty, Temp.Bill, 'Duplicate ID' AS [Alert] " & _
    "FROM Temp INNER JOIN MASTER ON Temp.[ID] = MASTER.ID;"
    Code:
    'Append Null ID to Alert Table
    
    StrSQL = "INSERT INTO Alerts ( PERIOD, [Id], [Transaction Source], Yes, [Hold], " & _
    "[Name], Project, Task, [Type], [Date], [Employee Name], Quantity, [Rate], " & _
    "UOM, [Cost], [field 17], [Amount], Comment, Field19, Bill, Alert ) SELECT " & _
    "Temp.PERIOD, Temp.[Id], Temp.[Transaction Source], Temp.Yes, Temp.Hold, " & _
    "Temp.[Name], Temp.Project, Temp.Task, Temp.[Type], Temp.[Date], " & _
    "Temp.[Employee Name], Temp.Quantity, Temp.[Rate], Temp.UOM, Temp.[Cost], " & _
    "Temp.[17], Temp.[Amount], Temp.Comment, Temp.Empty, Temp.Bill, 'Null ID' AS [Alert] " & _
    "FROM Temp WHERE ((Temp.[ID]) = Null));"
    When I run these queries, I get multiple copies of the different examples that I run. I have included fake data (showing only 2 rows for sake of displaying important data):
    TEMP Table
    ID


    Employee Name
    12345 Tony Jones
    5678 New Employee Name
    Bob Smith

    Where in the example data, ID 12345 is a duplicate ID, 5678 is a new employee, and Bob Smith is a null ID. The data I get is similar to below:
    ALERTS Table
    ID
    Employee Name
    Alert
    12345 Tony Jones Duplicate ID
    5678 New Employee Name New Name
    Bob Smith Null ID
    12345 Tony Jones Duplicate ID
    5678 New Employee Name New Name
    Bob Smith Null ID
    12345 Tony Jones Duplicate ID
    5678 New Employee Name New Name
    Bob Smith Null ID

    Can anyone help guide me as to why these queries, ran only once, would produce 3+ copies of the data I need?

    Thank you for your help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Cannot use = Null as criteria, use Is Null. Review http://allenbrowne.com/casu-12.html

    Would have to know more about data in other tables (NameCard, Master) used in the queries.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Append Query For Single Record
    By burrina in forum Forms
    Replies: 8
    Last Post: 01-04-2013, 05:12 PM
  2. Append Query Creates a New Record
    By burrina in forum Queries
    Replies: 5
    Last Post: 01-01-2013, 07:27 PM
  3. Append Query For Single Record
    By burrina in forum Queries
    Replies: 3
    Last Post: 12-30-2012, 11:23 PM
  4. append query without duplicate record
    By smahdih in forum Queries
    Replies: 5
    Last Post: 11-16-2011, 12:29 AM
  5. Replies: 5
    Last Post: 11-03-2011, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums