Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with code 1

Status
Not open for further replies.

MA04

Technical User
Dec 21, 2004
162
GB
Hi all,

I downloaded this piece of code from the microsoft site which capitalises first letter of every name and places small caps on the rest of the name. But it seems to have one problem if the word "withe" is enterd it gets rid of the "e", i don't know why that is it seems to work in all other cases.

Here is the code:
Code:
Function Proper(x)
'  Capitalize first letter of every word in a field.
'  Use in an event procedure in AfterUpdate of control;
'  for example, [Last Name] = Proper([Last Name]).
'  Names such as O'Brien and Wilson-Smythe are properly capitalized,
'  but MacDonald is changed to Macdonald, and van Buren to Van Buren.
'  Note: For this function to work correctly, you must specify
'  Option Compare Database in the Declarations section of this module.
'
'  See Also: StrConv Function in the Microsoft Access 97 online Help.

Dim Temp$, C$, OldC$, i As Integer
  If IsNull(x) Then
    Exit Function
  Else
    Temp$ = CStr(LCase(x))
    '  Initialize OldC$ to a single space because first
    '  letter needs to be capitalized but has no preceding letter.
    OldC$ = " "
    For i = 1 To Len(Temp$)
      C$ = Mid$(Temp$, i, 1)
      If C$ >= "a" And C$ <= "z" And (OldC$ < "a" Or OldC$ > "z") Then
        Mid$(Temp$, i, 1) = UCase$(C$)
      End If
      OldC$ = C$
    Next i
    Proper = Temp$
  End If
End Function

P.S. I am calling the code in a textbox called name_input on its after update.

Any help very much appreciated, thanks in advance,
M-.
 
It could be that the code is not causing the problem. Check and make sure the text box property Allow AutoCorrect is set to No and see if you still have the problem.

Hope this helps.

OnTheFly
 
Thanks for that you are absolutely correct, there was nothing wrong with the code it was the textbox settings.

[thumbsup2]
M-.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top