Hi All,
I find myself faced with a variation on the usage of Proper Case that I can't find any reference to in a search of this section of the forum using keyword vbProperCase. The closest I've found is this thread: Numeric-Alpha propercase problem
I have a text field that I require to be in Proper Case. Getting to that point is no problem. The problem that I have is that some of the text in that field is made up of alpha-numeric strings that we use as equipment numbers. e.g. PU123 is a pump, TA123 is a tank, and so on.
I already use the following code to correct these instances after the whole field has been changed to Proper Case:
As you can see, I have a table of equipment prefixes that is tested against to do the corrections. The code currently checks to see if the test string is followed by a non alpha character, and if so then it will replace it with the test string in capitals as retrieved from the table.
It will also check to see if the test string exists on its own, surrounded by spaces, in which case it will also replace it.
What I can't seem to get my head around, though, is how to get the code to look at the second instance of the test string in the field. This becomes a problem if the field reads "Transfer Pump Pu123", as opposed to "Pu123 Transfer Pump".
The latter will be successfully corrected to read "PU123 Transfer Pump", but the former will be entirely left alone (and rightly so, according to the code in its current state), as the next character after the test string is an alpha character 'Pump'.
Any suggestions on how to get to the second instance of the test string in any given field where it appears more than once would be greatly appreciated.
Cheers,...Jon.
I find myself faced with a variation on the usage of Proper Case that I can't find any reference to in a search of this section of the forum using keyword vbProperCase. The closest I've found is this thread: Numeric-Alpha propercase problem
I have a text field that I require to be in Proper Case. Getting to that point is no problem. The problem that I have is that some of the text in that field is made up of alpha-numeric strings that we use as equipment numbers. e.g. PU123 is a pump, TA123 is a tank, and so on.
I already use the following code to correct these instances after the whole field has been changed to Proper Case:
Code:
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tblExclude")
RS.MoveFirst
Do While Not RS.EOF
[COLOR=seagreen] 'convert the test string to Proper Case[/COLOR]
strXstring = StrConv(RS!txtExclusion, vbProperCase)
[COLOR=seagreen]'get the length of the test string[/COLOR]
intXstringLength = Len(strXstring)
[COLOR=seagreen]'get the string containing the test string from the field Title2[/COLOR]
Me.Title2.SetFocus
strTitle2 = Me.Title2.Text
[COLOR=seagreen]'find where in the field Title2 the test string resides[/COLOR]
varXstringStart = InStr(strTitle2, strXstring)
[COLOR=seagreen]'identify the position in the string of the next character after the test string[/COLOR]
If varXstringStart <> 0 Then
intContNum = intXstringLength + varXstringStart
Else
intContNum = 1
End If
[COLOR=seagreen]'gets the first character after the test string[/COLOR]
strContChar = Mid(strTitle2, intContNum, 1)
[COLOR=seagreen]'tests to see if strContChar is an Alpha character,[/COLOR]
[COLOR=seagreen] 'if so then the test string is likely to be a[/COLOR]
[COLOR=seagreen] 'part of a word and must remain in Proper Case.[/COLOR]
[COLOR=seagreen] 'If it's not an Alpha character then the test string[/COLOR]
[COLOR=seagreen] 'is replaced with Upper Case characters.[/COLOR]
If Not (Asc(strContChar) > 65 And Asc(strContChar) < 91) And Not (Asc(strContChar) > 97 And Asc(strContChar) < 123) Then
Me.Title2.SetFocus
Me.Title2.Value = Replace(strTitle2, strXstring, RS!txtExclusion)
Else
End If
[COLOR=seagreen]'if the test string appears on its own then it is capitalised as well[/COLOR]
If varXstringStart > 1 Then
strPrev = Mid(strTitle2, (varXstringStart - 1), 1)
If strPrev = " " And strContChar = " " Then
Me.Title2.SetFocus
Me.Title2.Value = Replace(strTitle2, strXstring, RS!txtExclusion)
Else
End If
Else
End If
[COLOR=seagreen]'moves to the next test string in the table[/COLOR]
RS.MoveNext
Loop
As you can see, I have a table of equipment prefixes that is tested against to do the corrections. The code currently checks to see if the test string is followed by a non alpha character, and if so then it will replace it with the test string in capitals as retrieved from the table.
It will also check to see if the test string exists on its own, surrounded by spaces, in which case it will also replace it.
What I can't seem to get my head around, though, is how to get the code to look at the second instance of the test string in the field. This becomes a problem if the field reads "Transfer Pump Pu123", as opposed to "Pu123 Transfer Pump".
The latter will be successfully corrected to read "PU123 Transfer Pump", but the former will be entirely left alone (and rightly so, according to the code in its current state), as the next character after the test string is an alpha character 'Pump'.
Any suggestions on how to get to the second instance of the test string in any given field where it appears more than once would be greatly appreciated.
Cheers,...Jon.