I'm trying to convert text to sentence case, ie capitalized first letter of the text box. The input will always be just one sentence, so I just converted everything to lower case and capitalized the first letter.
The problem begins here, I want some special combinations be left as upper case, abbrevations and such things. I found a code on the net, but it's not really working. Anyone sees anything wrong here or has some other solution?
there's table tblExceptions with coloumn Word where the exceptions are held.
tx
sample db
The problem begins here, I want some special combinations be left as upper case, abbrevations and such things. I found a code on the net, but it's not really working. Anyone sees anything wrong here or has some other solution?
there's table tblExceptions with coloumn Word where the exceptions are held.
Code:
Public Function LeaveCaps(strInputText) As String
On Error GoTo ErrorHandler
Dim strException As String
Dim strExceptionPlus As String
Dim strModifiedText As String
Dim strTestString As String
Dim strAppendChar As String
Dim i As Integer
Dim strTestChars As String
Dim a, b, c As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblExceptions")
'Do the initial conversion to mixed case (initial letter capitalized)
strModifiedText = UCase(Left(strInputText, 1)) & LCase(Right(strInputText, Len(strInputText) - 1))
'Set up string of punctuation marks to append to words being checked
strTestChars = " ,;.!?:-_()'" & Chr$(34)
'Restore the original capitalization of all words in table
Do While Not rst.EOF
strException = rst![Word]
'Search for word followed by each of the specified characters
For i = 1 To Len(strTestChars)
strAppendChar = Mid(strTestChars, i, 1)
strExceptionPlus = strException & strAppendChar
Debug.Print "Exception word: " & strExceptionPlus
strModifiedText = Replace(expression:=strModifiedText, _
Find:=strExceptionPlus, Replace:=strExceptionPlus)
Next i
rst.MoveNext
Loop
LeaveCaps = strModifiedText
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function
tx
sample db