+ Reply to Thread
Results 1 to 12 of 12

Modify code to show message box on duplicate entry

  1. #1
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Modify code to show message box on duplicate entry

    Hi everyone.. i am using the following code to enter data into a worksheet. I would like to make it so if the data being entered in textbox1 is already present in columnA of the worksheet then a message box will appear stating so, and none of the data from the form is entered onto the sheet.

    Please Login or Register  to view this content.
    Last edited by twofootgiant; 06-14-2011 at 09:42 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Modify code to show message box on duplicate entry

    Here's some code that I wrote for ComboBoxes but you can adapt it easily
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: Modify code to show message box on duplicate entry

    Sorry Roy,

    Thankyou for your help but I'm going to need a little more prompting on this one.

  4. #4
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: Modify code to show message box on duplicate entry

    Hey guys,

    any help with this issue? or any help modifying RoyUk's example code?

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Modify code to show message box on duplicate entry

    You'd better prevent that users enter data that are not being allowed.
    To show a message after all the work has been done must be rather frustrating.
    Use the principle: users can't make mistakes, programmers can forget to help users to do so.
    Last edited by snb; 06-21-2011 at 05:17 AM.



  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Modify code to show message box on duplicate entry

    If Column A contains unique entries then use a ComboBox instead of a TextBox

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Modify code to show message box on duplicate entry

    Amended the code to check with a TextBox
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: Modify code to show message box on duplicate entry

    Hi guys,

    we are looking thousands of entries, so I would ike to steer clear of using a combo box if i can.

    Perhaps I could activate the check seperately i.e. have another button on the userform 'check for duplicates'. Once the user has entered data into the first text box he would click that button, it would then check column A in the 'master' sheet for a duplicate entry. A textbox could then appear sayin if its OK to proceed or not.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Modify code to show message box on duplicate entry

    What's the problem using a combobox ?
    The user can enter any text (s)he wants. As long as the indexnumber is -1 it's not a duplicate.
    You can even use the combobox1_change event to change it's backcolor to indicate whether the text entered is a duplicate or not.

  10. #10
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: Modify code to show message box on duplicate entry

    Hi snb,

    Ok please can you show me how to modify my current code to using a combobox instead of textbox1?

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Modify code to show message box on duplicate entry

    Alternative using validation; no comboboxes needed.

    Cfr. the attachment
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: Modify code to show message box on duplicate entry

    So to change this to use with a userform am i right in thinking i would change it to

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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