Results 1 to 3 of 3

Thread: avoid duplication in SQL table

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    avoid duplication in SQL table

    hi
    i have a form in which there is a filelistbox.
    when the user clicks on the command Display,the filelistbox displays filenames present in a specific directory entered by the user
    spath=Trim(txtpath)
    File1.path=spath
    if the filelistbox contains 10 filenames,when the user clicks on OK,
    it will create 10 records in a table Article
    Private Sub cmdOK_Click()
    Rs1.Open"Select*from Article",SIC,adOpenStatic,adLockOptimistic
    For i=0 to File1.listCount-1
    Rs1.AddNew
    Rs1!Source=Trim(txtsource)
    Rs1!CompleteFile=File1.List(i)
    Rs1!Flag=0(Flag is of int type)
    Rs1.Update
    Rs1.close

    My problem is that if after adding the records corresponding to the list of filenames if the user enters by mistake the same path another time and clicks on Ok
    ,so in the Article table there will be duplication.how to avoid that if the user enters the same path twice or more to not add records to the Article table

    thanks

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: avoid duplication in SQL table

    SELECT DISTINCT.......
    Distinct does not give you dupes of records if i am not mistaken.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: avoid duplication in SQL table

    Just set the Path field as non-duplicable (Indexed as "Yes (No Duplicates)" in Access - if you're creating the table outside of Access, how you set this depends on how you're creating the table). Then adding a duplicate will raise an error, which you can trap.

    Braille, your method will work for selects, but I think what engnouna is asking for is a method to keep duplicate records from being saved to the database in the first place.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width