Results 1 to 2 of 2
  1. #1
    JennyL is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    51

    Lookup before appending records

    Hi,

    Is it possible to add DLookUp to check for duplicates before adding new records? In my case, the true duplicate record will consist of both ParentCIN & FeeCodeID fields.

    I only want the code to insert new fees if they don't exist, if they already have one exist (matching both parentCIN & FeeCodeID), then do not add those. What will be the best method to handle these "if", case statement?


    Private Sub CmdAddStandardFees_Click()
    On Error GoTo Err_CmdAddStandardFees_Click

    Dim sSQL As String
    If Me.Dirty Then Me.Dirty = False


    sSQL = "INSERT INTO Tbl_CustomerFeeSchedule (FeeCodeID, ParentCIN ) " _
    & "SELECT tbl_FeeTable.FeeCodeID," & [Forms]![frm_ListOfParents]![ParentCIN] & " AS ParentCIN " _
    & "FROM tbl_FeeTable;"
    Debug.Print sSQL
    CurrentDb.Execute sSQL, dbFailOnError

    Exit_CmdAddStandardFees_Click:


    Exit Sub

    Err_CmdAddStandardFees_Click:
    MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
    Resume Exit_CmdAddStandardFees_Click
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Sure, you can test first:

    Code:
    If DCount(...) > 0 Then
      MsgBox "Already exists!"
    Else
      'Your insert code here
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 05-20-2014, 11:51 AM
  2. Appending only records which have changed.
    By Miquel1 in forum Queries
    Replies: 3
    Last Post: 01-10-2014, 08:25 AM
  3. Message before Appending Records
    By Lorlai in forum Programming
    Replies: 3
    Last Post: 03-19-2013, 04:51 PM
  4. Appending inventory records with current price records
    By sberti in forum Database Design
    Replies: 8
    Last Post: 11-29-2012, 10:24 PM
  5. Key violation when appending records
    By slaterino in forum Programming
    Replies: 10
    Last Post: 08-26-2010, 08:25 AM

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