+ Reply to Thread
Results 1 to 9 of 9

Help preventing userform duplicates

  1. #1
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Help preventing userform duplicates

    The first field in my userform is to assign a serial number to a product. What can I do to prevent someone from using that same serial number to input a new product? I'd like some kind of error message stating that the serial number is already in use.
    Last edited by nohero; 06-09-2011 at 08:41 AM.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Help preventing userform duplicates

    HI,

    You can probably use a "Match" function, but here's a bit of code that I used to validate if nr. exist. This should give you some ideal.

    Please Login or Register  to view this content.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Help preventing userform duplicates

    Trying to get this going, I'm a newbie and still don't have a lot of experience so I'm unsure of this one line:

    With Lws.Range("D6:D" & Llrow)

    What am I customizing to my workbook in this line? Does Lws represent the worksheet that the field's data is going to and does the information in the brackets point to column that the previous entries are being stored in?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help preventing userform duplicates

    Hello nohero,

    I am not sure about your meaning of "userform". Are you referring to a worksheet or a VBA UserForm? If people are uncertain of what you mean then you are likely not to get a answer you expect.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Help preventing userform duplicates

    HI,

    The code:

    Please Login or Register  to view this content.
    The code looks in column D to see it item exsit if it does it will display the "MsgBox".

    I hope this helps

  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: Help preventing userform duplicates

    I wouldn't allow users to input a serial number, auto-generate it in the UserForm. I've posted code to do this but post back if that's something that would work
    Hope that helps.

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

    Free DataBaseForm example

  7. #7
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Help preventing userform duplicates

    Actually I can't just auto-assign serial numbers. The serial numbers are assigned at an earlier time and the product is branded with it. I'm just trying to prevent someone from entering a product twice or having 2 products with the same serial.

    I currently have checks for each textbox in my userform, I was thinking I could have just another check for that textbox when they try to submit the entire form... not necessarily when they try to tab off the serial number field.

    To help me I'll give an example of one of my checks:

    Please Login or Register  to view this content.
    I was hoping I could have some coding added after that last check that looks for a duplicate serial number and prevents susbmission of the form if it exists. The data from that textbox gets stored in column A on a worksheet called ProductData. So I basically need it to check ALL of column A on that sheet and return the error if it finds a duplicate.

    I tried working with some of the suggestions posted already but they are a little foreign to me... curse my underdeveloped brain! I wasn't able to get them working so I figured I'd give a little more detail to my situation in hopes that someone can give me the "VBA for Dummies" version that I can mostly copy and paste.

    Or feel free to explain what each line of the code is doing, you know, all that "teach a man to fish" stuff... but you'll have it dumb it down for me if you choose that option.

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

    Re: Help preventing userform duplicates

    You can use a worksheet function to checl

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Help preventing userform duplicates

    Ok, thanks Roy. This code worked perfectly, just needed to point it to the right sheet and column but now it's checking for me!

    With what I have here now I might just split this up into 2 checks so that I can get 2 different error messages depending on what triggered the fail on the check.

    Sorry for the delayed response and thank you for the help yet again.

+ 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