Question on InStr() Function

  • InStr(start, string1, string2, compare)

    How do I get the string2 argument to be case sensitive?

    Example:  I have data in a field that is both uppercase and lower case.  However, all the uppercase is listed first in the field.  I am wanting to use the InStr() function to determine the first position of a lowercase char in the string.  I will then use the return in a Left() function to be rid of all lowercase char using an update query.

    Greg

  • Search for Instr in the VBA help file.  You just need to set the compare option to binary compare.  IIRC, the compare constant is something like acCompareBinary, or something like that.  It's all in the help file.

    HTH,

    Rich

  • Settings

    The compare argument settings are:

    ConstantValueDescription
    vbUseCompareOption-1Performs a comparison using the setting of the Option Compare statement.
    vbBinaryCompare0Performs a binary comparison.
    vbTextCompare1Performs a textual comparison.
    vbDatabaseCompare2Microsoft Access only. Performs a comparison based on information in your database.
  • Is your object only to change lower case characters to upper case?  You don't need to know where those characters exist, just use the UPPER sql command.  Of course it will also change the current text in upper case to upper case but then we shouldn't really care.

     

     

  • If the goal is to change the whole string to upper or lower, you would use UCase or LCase in VBA.  (You would not want to use a T-SQL command in VBA by mistake)

  • Hi Greg,

    You will have to write yourself a function to do this. Try the sample code from this url where the question was asked and answered fairly well.

    http://forums.aspfree.com/archive/t-48781/Access-DB-using-VB-to-select-messages-which-contain-Capitals

    The code you are after is at the end of the link. The code is fairly well documented too. You won't need all of the code.

     

    Hope this helps

    Michael

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply