cheack duplicate data when enter in table

Last post 11-07-2009 6:42 AM by losssoc. 4 replies.

Sort Posts:

  • cheack duplicate data when enter in table

    11-01-2009, 2:50 PM
    • Member
      point Member
    • hasnat288
    • Member since 11-01-2009, 7:40 PM
    • Posts 1

    hi. i am a new person. i need some help with access.what i need, when im enterning some one name in my table it should check, does it has the same name before. if im entering his name for the 3rd time it gonna ask me to give 1 unique no. for the first 3 same name.

  • Re: cheack duplicate data when enter in table

    11-01-2009, 4:02 PM
    • Member
      638 point Member
    • losssoc
    • Member since 04-24-2008, 5:53 AM
    • Posts 212

    Are you using an access program, i.e. Aceess 2007, Access 2003?, or are you using Visual Studio and using an access database?



  • Re: cheack duplicate data when enter in table

    11-04-2009, 3:11 AM

    Hi hasnat288,

    Could you show us more details? We can't understand the question clearly. Also, I suggest you to post this question in Access forum here:

    http://forums.asp.net/55.aspx

    Thanks. 

    David Qian
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: cheack duplicate data when enter in table

    11-07-2009, 1:08 AM
    • Member
      331 point Member
    • cnranasinghe
    • Member since 10-27-2009, 12:41 AM
    • Sri Lanka
    • Posts 85

    There no clear explanation of the Business logic. Checking a name against the DB is simple. Provide more details for a proper answere. Database, Laguage (VB.NET / C#)?

  • Re: cheack duplicate data when enter in table

    11-07-2009, 6:42 AM
    Answer
    • Member
      638 point Member
    • losssoc
    • Member since 04-24-2008, 5:53 AM
    • Posts 212

    The below code is an example of checking to see if last name exists in a table. This is taken from Access 2007 Inside Out page 1073.

    You should buy the reference book - very helpful!


    Private Sub Form_BeforeUpdate(Cancel As Integer)

    Dim rst as DAO.Recordset, strNames As String

    'if on a new row

    If (Me.NewRecord = True) Then

    'check for similar names

    If Not IsNothing(Me.LastName) Then

    'open a recordset to look for similar names

    Set rst = CurrentDb.OpenRecordset("SELECT LastName, FirstName FROM " & _

    "tblContacts WHERE Soundex([LastName]) = '" & _

    Soundex(Me.LastName) & "'")

    'If got some similar names, collect them for the message

    Do Until rst.EOF

    strNames = StrNames & rst!LAstName & ", " & rst!FirstName & vbCrLf

    rst.MoveNext

    Loop

    'done with the recordset

    rst.Close

    Set rst = Nothing

    'see if we got some similar names

    If len(strNames)> 0 Then

    'Issue warning

    If vbNo = MessageBox("contacts found with similar last names already saved in the database: " & vbCrLf & vbCrLf & _

    strNames & vbCrLf & _

    "Are you sure this contact is not a duplicate?", _

    vbQuestion + vbYesNo + vbDefaultButton2, gstrAppTitle) Then

    'cancel the save

    Cancel = True

    End If

    End If

    End If

    End If

    End Sub


Page 1 of 1 (5 items)