A
Albert S.
Hello,
I am trying to create a new Proper Case function that will compare words in
a field to a table (tblNames) containing the correct capitalization we want
to use.
For instance Roman numerals, certain codes, abbreviations, foreign words etc.
I was thinking of breaking the data into an array with space as the
delimiter, but I also need to examine words that are adjacent to or are
embedded in characters such as:
word1 word2 word3 Hob.iii.3a.
Hob.iii.3a needs to be Hob.III.3a - propercase for Hob. (not in table),
lookup in table for iii (in table as III) and proper case for 3a (not in
table).
I only have to catch these characters (I hope!): / - [ ] { } . ; : ( )
So what I want to do is use the split() funtion to create an array of each
word so I can match them to the table, but this would entail multiple
delimiters.
I was thinking to delimit by space first then by the symbols, but wasn't
sure how to get an array from more than one delimiter.
Here is what I have so far:
Public Function NewProperLookup(ByVal InText As Variant) As Variant
Dim OutText As String
Dim i As Integer
Dim j As Integer
Dim D As String
Dim strWord As String
Dim arrTitle As Variant
Dim db As Database
Dim rs As DAO.Recordset
Dim cSQL As String
Dim strLook As String
Dim intSection As Integer
Dim blnForce As Boolean
Set db = CurrentDb
If VarType(InText) <> 8 Then
NewProperLookup = InText
Else
arrTitle = split(InText, " ", -1, vbTextCompare)
For i = 0 To UBound(arrTitle)
Debug.Print arrTitle(i)
strLook = arrTitle(i)
cSQL = "SELECT [Name] FROM tblNames WHERE [Name] = " & Chr(34) &
strLook & Chr(34)
Set rs = db.OpenRecordset(cSQL)
If rs.BOF And rs.EOF Then 'no match - process word
If IsAlpha(strLook) Then
OutText = Trim(OutText & " " & UCase(Left(strLook, 1)) &
LCase(Mid(strLook, 2)))
Else
blnForce = False
strWord = ""
For j = 1 To Len(strLook) 'force an uppercase after a
symbol
D = Mid(strLook, j, 1)
If blnForce Then
D = UCase(D)
blnForce = False
End If
If D = "/" Or D = "-" Or D = "{" Or D = "}" Or D =
"[" Or D = "]" Or D = "." Or D = ";" _
Or D = ":" Or D = "(" Or D = ")" Then
blnForce = True
End If
strWord = strWord & D
Next j
OutText = Trim(OutText & " " & strWord)
End If
Else
strLook = rs!Name
OutText = OutText & " " & strLook
End If
Next i
db.Close
NewProperLookup = OutText
End If
End Function
Any suggestions appreciated!
I am trying to create a new Proper Case function that will compare words in
a field to a table (tblNames) containing the correct capitalization we want
to use.
For instance Roman numerals, certain codes, abbreviations, foreign words etc.
I was thinking of breaking the data into an array with space as the
delimiter, but I also need to examine words that are adjacent to or are
embedded in characters such as:
word1 word2 word3 Hob.iii.3a.
Hob.iii.3a needs to be Hob.III.3a - propercase for Hob. (not in table),
lookup in table for iii (in table as III) and proper case for 3a (not in
table).
I only have to catch these characters (I hope!): / - [ ] { } . ; : ( )
So what I want to do is use the split() funtion to create an array of each
word so I can match them to the table, but this would entail multiple
delimiters.
I was thinking to delimit by space first then by the symbols, but wasn't
sure how to get an array from more than one delimiter.
Here is what I have so far:
Public Function NewProperLookup(ByVal InText As Variant) As Variant
Dim OutText As String
Dim i As Integer
Dim j As Integer
Dim D As String
Dim strWord As String
Dim arrTitle As Variant
Dim db As Database
Dim rs As DAO.Recordset
Dim cSQL As String
Dim strLook As String
Dim intSection As Integer
Dim blnForce As Boolean
Set db = CurrentDb
If VarType(InText) <> 8 Then
NewProperLookup = InText
Else
arrTitle = split(InText, " ", -1, vbTextCompare)
For i = 0 To UBound(arrTitle)
Debug.Print arrTitle(i)
strLook = arrTitle(i)
cSQL = "SELECT [Name] FROM tblNames WHERE [Name] = " & Chr(34) &
strLook & Chr(34)
Set rs = db.OpenRecordset(cSQL)
If rs.BOF And rs.EOF Then 'no match - process word
If IsAlpha(strLook) Then
OutText = Trim(OutText & " " & UCase(Left(strLook, 1)) &
LCase(Mid(strLook, 2)))
Else
blnForce = False
strWord = ""
For j = 1 To Len(strLook) 'force an uppercase after a
symbol
D = Mid(strLook, j, 1)
If blnForce Then
D = UCase(D)
blnForce = False
End If
If D = "/" Or D = "-" Or D = "{" Or D = "}" Or D =
"[" Or D = "]" Or D = "." Or D = ";" _
Or D = ":" Or D = "(" Or D = ")" Then
blnForce = True
End If
strWord = strWord & D
Next j
OutText = Trim(OutText & " " & strWord)
End If
Else
strLook = rs!Name
OutText = OutText & " " & strLook
End If
Next i
db.Close
NewProperLookup = OutText
End If
End Function
Any suggestions appreciated!