Initial Cap in a text box

J

JackBuff

I have set up a form to capture information about clients.
I would like to be able to have the Name fields (First,
Last) automatically capitalize the first character. Your
help is appreciated.
 
M

Mike Labosh

I have set up a form to capture information about clients.
I would like to be able to have the Name fields (First,
Last) automatically capitalize the first character. Your
help is appreciated.

Public Function TCase(ByVal value As String) As String

Dim i As Integer

Mid$(value, 1, 1) = UCase$(Mid$(value, 1, 1))

i = 1

While i <> 0
i = InStr(i, value, " ", vbBinaryCompare)

If i <> 0 And Len(value) >= i Then
i = i + 1
Mid$(value, i, 1) = UCase$(Mid$(value, i, 1))
End If

Wend

TCase = value

End Function


Now, on the on-user-left-the-control (whatever it's called) event, you do
something like this:

MyControl = TCase(MyControl)

However, there is a subtle weakness in this code. "bob smith" will turn
into "Bob Smith", but "martia van der hoffen-schlager" will become "Martia
Van Der Hoffen-schlager", where Van and Der should remain lower case.
Getting that to work will require you to have a table of LastNamePrefixes,
wherein each term of the name would have to be parsed against the whole
list. That's some pretty hefty string munching. I have three pages of .NET
code that does this, and while elegant, it was painful to develop. Also
note that the s in schlager (hyphenated last name) should be capitalized,
but didn't because it did not follow a space.
 
F

fredg

I have set up a form to capture information about clients.
I would like to be able to have the Name fields (First,
Last) automatically capitalize the first character. Your
help is appreciated.

Code the AfterUpdate event of the control:
Me![ControlName] = StrConv(Me![ControlName],vbProperCase)

Be aware that this will not properly capitalize all words and names,
as some names must always be in all caps (IBM, CBS, etc.), some never
capitalized (e.e. cummings), some have 2 capitals in the name
(McDonald, O'Connor) and some have a mixed set of capitalized names
(van der Meer), as well as all hyphenated names.

The best way to accurately handle names like these, that I know of, is
to have a table of exceptions, and DLookUp the table for that
particular name or word before changing it.
You would need to create a User Defined function to do all of this and
regularly maintain the list of names, adding new names as needed.

And, after all is said and done, there are still some words and names
that can be written both ways (O'Connor, O'connor, McDonald, Mcdonald)
as well as others whose capitalization depends on usage (ABC, abc,
Xerox, xerox, Access, access).
 
M

Mike Labosh

Me![ControlName] = StrConv(Me![ControlName],vbProperCase)

WHOA I've been a pro developer in access & vb since 1992 and I never new
this StrConv(vbProperCase) was in there. THIS RULES!
 
J

jackbuff

-----Original Message-----
I have set up a form to capture information about clients.
I would like to be able to have the Name fields (First,
Last) automatically capitalize the first character. Your
help is appreciated.

Code the AfterUpdate event of the control:
Me![ControlName] = StrConv(Me![ControlName],vbProperCase)

Be aware that this will not properly capitalize all words and names,
as some names must always be in all caps (IBM, CBS, etc.), some never
capitalized (e.e. cummings), some have 2 capitals in the name
(McDonald, O'Connor) and some have a mixed set of capitalized names
(van der Meer), as well as all hyphenated names.

The best way to accurately handle names like these, that I know of, is
to have a table of exceptions, and DLookUp the table for that
particular name or word before changing it.
You would need to create a User Defined function to do all of this and
regularly maintain the list of names, adding new names as needed.

And, after all is said and done, there are still some words and names
that can be written both ways (O'Connor, O'connor, McDonald, Mcdonald)
as well as others whose capitalization depends on usage (ABC, abc,
Xerox, xerox, Access, access).
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
Thanks , I will give this a try.
 
L

Larry R Harrison Jr

Mike Labosh said:
Public Function TCase(ByVal value As String) As String

Dim i As Integer

Mid$(value, 1, 1) = UCase$(Mid$(value, 1, 1))

i = 1

While i <> 0
i = InStr(i, value, " ", vbBinaryCompare)

If i <> 0 And Len(value) >= i Then
i = i + 1
Mid$(value, i, 1) = UCase$(Mid$(value, i, 1))
End If

Wend

TCase = value

End Function


Now, on the on-user-left-the-control (whatever it's called) event, you do
something like this:

MyControl = TCase(MyControl)

However, there is a subtle weakness in this code. "bob smith" will turn
into "Bob Smith", but "martia van der hoffen-schlager" will become "Martia
Van Der Hoffen-schlager", where Van and Der should remain lower case.
Getting that to work will require you to have a table of LastNamePrefixes,
wherein each term of the name would have to be parsed against the whole
list. That's some pretty hefty string munching. I have three pages of .NET
code that does this, and while elegant, it was painful to develop. Also
note that the s in schlager (hyphenated last name) should be capitalized,
but didn't because it did not follow a space.


You right there have made one of the main arguments against last-name
hyphenation. I am opposed to it--for reasons that I think it's
anti-family (it makes a woman too focused on her "independence" when
she's now part of a marriage and should be focused more on that) and
there is also this practical consideration. Why are there always
people like this introducing wrinkles into a system and requiring us
database designers to design entire complicated schemes to deal with
these exceptions?

Me? Personally, I'd tend to just have one "last name" field and let
the chips fall where they may. Why should I have to spend hours
developing a whole new routine to deal with a needless wrinkle which
has no business existing?

LRH
 
Top