+ Reply to Thread
Results 1 to 8 of 8

Duplicates from tab/space(s)

  1. #1
    Registered User
    Join Date
    09-11-2009
    Location
    MN
    MS-Off Ver
    Office 2010
    Posts
    48

    Duplicates from tab/space(s)

    Background:

    I have a workbook with a userform that we use to keep track of inventory. About 20+ people have access to open the userform and enter an asset "number". The userform then looks to sheet and if it finds a matching asset number on the sheet it will populate the other fields on the form. The user can then make changes and resubmit the information, at which point it will update the existing asset row information with the new info. If it doesn't find a matching asset number, the other fields will be blank and the user can fill in what they have and when they hit submit it will create a new row.

    We have people using both Excel 2003 and 2007.

    I am using the following code inside the CompAsset.text field to prevent them from using a space:
    Please Login or Register  to view this content.

    Problem:
    Somehow, from time to time, as the user is entering in the asset information and they try to tab to the next field it actually puts a tab within the text box. Othertimes, despite the code above, they manage to get an extra space or spaces at the end of the asset. These extra spaces cause it not to find a match on the worksheet and once the user hits submit a new record is created and we end up with duplicates that usually have different information. The users often times don't realize this has happened and just assume that the record didn't previously exist.

    I unfortunately can't limit the number of characters the asset textbox can have, nor can I restrict the field to only allowing numbers.

    I'm not sure what else you might need to know, but any help solving this would be greatly appreciated!!

    Thank you!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicates from tab/space(s)

    You can remove that separate code and create a CompAsset_Change macro that triggers automatically each time the CompAsset field is changed. That macro can handle all the stripping for you in realtime, making it unnecessary to do it later.

    Please Login or Register  to view this content.

    This actually works as they type... so pressing the spacebar will not even result in a space being seen in the textbox.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-11-2009
    Location
    MN
    MS-Off Ver
    Office 2010
    Posts
    48

    Re: Duplicates from tab/space(s)

    I will give this a try. After adding the option explicit some of it errored out because I had variants that weren't expressly defined, so I'll have to go back and add them in before the users can try it out.

    I don't know what caused tab not to tab into the next field before but hopefully it won't matter and this will take care of it.

    Thanks!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicates from tab/space(s)

    Option Explicit should be turned on automatically at the top of all your modules. THere's nothing more frustrating than hunting 100s of lines of code looking for a typo you missed. Option Explicit points out those errors for you.

  5. #5
    Registered User
    Join Date
    09-11-2009
    Location
    MN
    MS-Off Ver
    Office 2010
    Posts
    48

    Re: Duplicates from tab/space(s)

    That is a good idea. I will have to do that.
    I just rolled this out, so we'll see if that helps. But it does work like it should now. Thank you!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicates from tab/space(s)

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Duplicates from tab/space(s)

    hi, XLVBA, another option to use is:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicates from tab/space(s)

    Watersev, how does that stop typing non-alphanumeric characters? !@#$%^&*()...

+ 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