Page 3 of 3 FirstFirst 123
Results 31 to 32 of 32
  1. #31
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by accesstos View Post
    Hi all!
    Code:
    Function ProperAll(ByVal strIn As String, Optional ByVal SkipExceptions As Boolean = True) As String
        'Returns the strIn with all words in proper case
        'exept those that are in table tblCaseExceptions
        'if SkipExceptions is TRUE.
        Dim rsExp As dao.Recordset
        Dim i As Integer
        Dim intPos As Integer
        Dim strExp As String
        Dim strTemp As String
        Dim strW As String
        Dim varW As Variant
        
        On Error GoTo ErrHandler
        strTemp = strIn
        If SkipExceptions Then
            'Get the exceptions.
            Set rsExp = CurrentDb.OpenRecordset("SELECT CaseException FROM tblCaseExceptions", dbOpenForwardOnly)
            While Not rsExp.EOF
                strExp = rsExp(0)
                'Search for exception in temporary text.
                If InStr(1, strTemp, strExp, vbBinaryCompare) > 0 Then
                    'Remove the exception from temp text.
                    strTemp = Replace(strTemp, strExp, " ")
                End If
                rsExp.MoveNext
            Wend
        End If
        'Remove extra spaces.
        While InStr(1, strTemp, "  ") > 0
            strTemp = Replace(strTemp, "  ", " ")
        Wend
        'Get the remaining words.
        varW = Split(Trim(strTemp))
        'Convert the input text using only the remaining words.
        For i = LBound(varW) To UBound(varW)
            strW = varW(i)
            'Find the current word in text.
            intPos = InStr(intPos + 1, strIn, strW)
            'Convert it to proper case.
            Mid(strIn, intPos, Len(strW)) = StrConv(strW, vbProperCase)
            'Set the position in text to the end of this word.
            intPos = intPos + Len(strW)
        Next i
    ExitHere:
        'Return.
        ProperAll = strIn
        On Error Resume Next
        rsExp.Close
        Set rsExp = Nothing
        On Error GoTo 0
        Exit Function
    ErrHandler:
        Resume ExitHere
    End Function
    It looks like it's only matching when the case of the word in the input string matches exactly the case in the table. I think the idea is that you can input whatever case and it will be 'autocorrected' to the case within the table.

    I like the idea of being able to 'autocorrect' phrases and not just words. And I like that you can get rid of the regex. I wonder how long the exception list has to be before this route is less efficient than scanning the input string?

  2. #32
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by kd2017 View Post
    It looks like it's only matching when the case of the word in the input string matches exactly the case in the table. I think the idea is that you can input whatever case and it will be 'autocorrected' to the case within the table.
    By which way you think we can decide that the 'cat' in the original text is the CAT corporation and not the animal?
    I think that the 'autocorrect' demands a lot of work to be 'intelligent' enough.

    Quote Originally Posted by kd2017 View Post
    I like the idea of being able to 'autocorrect' phrases and not just words. And I like that you can get rid of the regex. I wonder how long the exception list has to be before this route is less efficient than scanning the input string?
    I think that the methods of the DAO.Recordset and methods like InStr() are too efficient to worry about the size of the exceptions list. On the contrary, DlookUp() is not. Replace() function is the most 'heavy' method of ProperAll().

    Cheers,
    John

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Proper Case
    By jonboy in forum Access
    Replies: 9
    Last Post: 04-05-2021, 01:49 AM
  2. Replies: 5
    Last Post: 05-14-2019, 07:48 AM
  3. Replies: 4
    Last Post: 04-28-2019, 07:19 PM
  4. Change text case from upper to proper case
    By s.nolan in forum Access
    Replies: 1
    Last Post: 12-02-2015, 10:56 AM
  5. Proper Case or Capitalization help
    By tshirttom in forum Programming
    Replies: 5
    Last Post: 03-23-2012, 10:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums