Uppercase Lowercase Format

wizcow

Registered User.
Local time
Today, 05:28
Joined
Sep 22, 2001
Messages
236
Hi

The users of my database are entering some data, all in uppercase, some in lowercase, and some mixed. This makes the text in the combo boxes etc. look bad.

Is there a way that I can set the format so it will always display the first letter of each word in uppercase?

Thanks
Tom
 
There is a way to force all uppercase or lower case....

That any help ???
 
I have read about a function

StrConv (textboxname,vbProperCase)

This is supposed to force the first letter uppercase in all words.
(which is what I want)
But I don't know how to use it.

Tom
 
wizcow,

this will not force the user to use proper case (or convert it as they type) but it can be used to redisplay the data in propercase.

The statement is as mentioned, except the conversion variable is as follows:

=StrConv([Text],3)

where [Text] is your text string (obviously).

3 gives you proper case (1 upper / 2 lower - just for reference)

HTH

Brad.
 
While the VB Case convertors work OK, they don't handle some names correctly.

I wrote/butchered the following code some time ago when preparing a mailing list for a company.

Paste the code below into a new module and use the Mixed_Case routine.

Public Function Mixed_Case(str As Variant) As String
'returns modified string, first character of each word us uppercase
'all others lower case
Dim ts As String, ps As Integer, char2 As String
If IsNull(str) Then
Mixed_Case = ""
Exit Function
End If
str = Trim(str)
If Len(str) = 0 Then
Mixed_Case = ""
Exit Function
End If
ts = LCase$(str)
ps = 1
ps = first_letter(ts, ps)
special_name ts, 1 'try to fix the beginning
Mid$(ts, 1) = UCase$(Left$(ts, 1))
If ps = 0 Then
Mixed_Case = ts
Exit Function
End If
While ps <> 0
If is_roman(ts, ps) = 0 Then 'not roman, apply the other rules
special_name ts, ps
Mid$(ts, ps) = UCase$(Mid$(ts, ps, 1)) 'capitalize the first letter
End If
ps = first_letter(ts, ps)
Wend
Mixed_Case = ts
End Function
Private Sub special_name(str As String, ps As Integer)
'expects str to be a lower case string, ps to be the
'start of name to check, returns str modified in place
'modifies the internal character (not the initial)
Dim char2 As String
char2 = Mid$(str, ps, 2) 'check for special cap rules
If (char2 = "mc" Or char2 = "o'") And Len(str) > ps + 1 Then 'Mc form
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If
End Sub
Private Function first_letter(str As String, ps As Integer) As Integer
'ps=starting point to search (starts with character AFTER ps)
'returns next first letter, 0 if no more left
Dim P2 As Integer, P3 As Integer, s2 As String
s2 = str
P2 = InStr(ps, str, " ") 'points to next blank, 0 if no more
P3 = InStr(ps, str, "-") 'points to next hyphen, 0 if no more
If P3 <> 0 Then
If P2 = 0 Then
P2 = P3
ElseIf P3 < P2 Then
P2 = P3
End If
End If
If P2 = 0 Then
first_letter = 0
Exit Function
End If
'first move to first non blank, non punctuation after blank
While is_alpha(Mid$(str, P2)) = False
P2 = P2 + 1
If P2 > Len(str) Then 'we ran off the end
first_letter = 0
Exit Function
End If
Wend
first_letter = P2
End Function
Public Function is_alpha(ch As String)
'returns true if this is alphabetic character
'false if not
Dim c As Integer
c = Asc(ch)
Select Case c
Case 65 To 90
is_alpha = True
Case 97 To 122
is_alpha = True
Case Else
is_alpha = False
End Select

End Function
Private Function is_roman(str As String, ps As Integer) As Integer
'starts at position ps, until end of word. If it appears to be
'a roman numeral, than the entire word is capped in passed back
'string, else no changes made in string
'returns 1 if changes were made, 0 if no change
Dim mx As Integer, P2 As Integer, flag As Integer, i As Integer
mx = Len(str) 'just so we don't go off the edge
P2 = InStr(ps, str, " ") 'see if there is another space after this word
If P2 = 0 Then
P2 = mx + 1
End If
'scan to see if any inappropriate characters in this word
flag = 0
For i = ps To P2 - 1
If InStr("ivxIVX", Mid$(str, i, 1)) = 0 Then
flag = 1
End If
Next i
If flag Then
is_roman = 0
Exit Function 'this is not roman numeral
End If
Mid$(str, ps) = UCase$(Mid$(str, ps, P2 - ps))
is_roman = 1
End Function
 

Users who are viewing this thread

Back
Top Bottom