+ Reply to Thread
Results 1 to 5 of 5

RegEx Object Error

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    RegEx Object Error

    Hi all,

    I am using a simple Regular Expression to check the contents of a Text Box on a user form but it is all of a sudden throwing up and error -

    Run-time error '5021':

    Application-defined or object-defined error.
    This is the code I use for the call -

    Please Login or Register  to view this content.
    and this is the function for the RegEx -

    Please Login or Register  to view this content.
    The thing that has baffeled me is that this was working, and has been for a while, and then all of a sudden it started throwing up the error every time. I have checked everything I can think of that could cause an error like this but I am drawing a blank.

    Any help is greatly appriciated.
    Thanks.
    Last edited by Leith Ross; 07-01-2009 at 11:49 PM. Reason: Changed color from yellow to red.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: RegEx Object Error

    I found that the error only occurs with the second regex pattern, i.e. when TextType <> "Special". It looks like the "-&" part is being interpreted as a range, so you need to escape the hyphen to prevent this, as shown in the code below.

    Also, when posting a problem try to make it easily reproducible for people to help you by including a test subroutine which simply calls the function in question with the correct data type (a string), rather than all the superfluous code for your call.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: RegEx Object Error

    ... or just make the hyphen the last character:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  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: RegEx Object Error

    Hello duckboy1981,

    It isn't clear to me how this code ever worked correctly. From the post I gather you want to look for any character that isn't part of the pattern. This will will do that. If any character is not part of the valid characters specified, it will be considered an invalid entry.
    Please Login or Register  to view this content.
    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
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: RegEx Object Error

    Thanks guys, thats sorted now.

+ 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