+ Reply to Thread
Results 1 to 7 of 7

Prevent Duplicate Entries when Editing Data using Userform

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-14-2017
    Location
    South Africa
    MS-Off Ver
    Office 2010
    Posts
    148

    Prevent Duplicate Entries when Editing Data using Userform

    Good Day

    I have using this user form to add, edit, delete data. The userform thus far works brilliantly thanks to this forum and its members who assisted me.

    I have this issue whereby when I am editing data, I want the system to check that the edited data is duplicated or not. The fields I am particularly concerned about are: ALB Tag# and the Power on Password and Computer Name

    I have attached my spreadsheet for better clarity

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Prevent Duplicate Entries when Editing Data using Userform

    Something like:


    
    Dim Z as range
    
    Private Sub txtTag_Change()  'Add DBN Prefix
    Static abort As Boolean
        If abort Then abort = False: Exit Sub
        With txtTag
              If Not .Text Like "DBN*" And .Text <> vbNullString Then
                abort = True
                .Text = "DBN" & .Text
            End If
        End With
        
    Set z= Columns(10).Find(txtTag.text, LookIn:=xlValues, Lookat:=xlWhole).row
    
    If Z = txtTag.Text Then
    MsgBox "Duplicate Entry", vbOKOnly
    txtTag.Clear
    End If
    
    End Sub
    Last edited by mehmetcik; 05-01-2017 at 05:51 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    04-14-2017
    Location
    South Africa
    MS-Off Ver
    Office 2010
    Posts
    148

    Re: Prevent Duplicate Entries when Editing Data using Userform

    HI

    Tried the code and getting error on txtTag.Clear "variable not defined"

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,271

    Re: Prevent Duplicate Entries when Editing Data using Userform

    Private Sub txtTag_Change()  'Add DBN Prefix
        Static abort As Boolean
        If abort Then abort = False: Exit Sub
        With txtTag
              If Not .Text Like "DBN*" And .Text <> vbNullString Then
                abort = True
                .Text = "DBN" & .Text
            End If
        End With
        
        If Not IsError(Application.Match(txtTag.Text, Columns(10), 0)) Then
            MsgBox "Duplicate Entry", vbOKOnly
            txtTag = vbNullString
        End If
    End Sub
    Last edited by bakerman2; 05-04-2017 at 01:33 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Prevent Duplicate Entries when Editing Data using Userform

    Dim Z as range
    
    Private Sub txtTag_Change()  'Add DBN Prefix
    Static abort As Boolean
        If abort Then abort = False: Exit Sub
        With txtTag
              If Not .Text Like "DBN*" And .Text <> vbNullString Then
                abort = True
                .Text = "DBN" & .Text
            End If
        End With
    
    On Error Resume Next 
    
    Set z= Columns(10).Find(txtTag.text, LookIn:=xlValues, Lookat:=xlWhole)
    
    On Error Goto 0
    
    
    If Z = txtTag.Text Then
    MsgBox "Duplicate Entry", vbOKOnly
    txtTag.Clear
    End If
    
    End Sub
    Last edited by mehmetcik; 05-05-2017 at 01:06 PM.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,271

    Re: Prevent Duplicate Entries when Editing Data using Userform

    @ mehmetcik

    Code goes into debug on this line after typing first number.

    If Z = txtTag.Text Then
    Also still error on.

    txtTag.Clear
    as OP responded in Post#3

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Prevent Duplicate Entries when Editing Data using Userform

    My Mistake

    Try this instead

    
    Private Sub txtTag_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
    Dim Z As Variant
    Dim t As String
    Static abort As Boolean
        If abort Then abort = False: Exit Sub
        With txtTag
              If Not .Text Like "DBN*" And .Text <> vbNullString Then
                abort = True
                .Text = "DBN" & .Text
            End If
        End With
    
    'On Error Resume Next
    t = txtTag.Text
    Set Z = Columns("J:J").Find(t)
    
    On Error GoTo 0
    
    
    If Z = txtTag.Text Then
    MsgBox "Duplicate Entry", vbOKOnly
    txtTag.Value = ""
    End If
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Prevent Duplicate entries in multiple column from VBA Userform
    By excel_126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 03:13 AM
  2. Prevent duplicate entries in Data Validation List By code
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-26-2014, 04:56 PM
  3. Prevent duplicate entries in Data Validation List By code
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2014, 04:37 PM
  4. Replies: 0
    Last Post: 06-14-2012, 12:38 PM
  5. Prevent Duplicate Entries
    By whousedmy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-17-2010, 11:40 AM
  6. To prevent duplicate entries using Data validation.
    By legendkiller420 in forum Excel General
    Replies: 3
    Last Post: 07-09-2010, 07:47 AM
  7. Prevent Duplicate Entries
    By luckyphil in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2007, 08:20 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1