Using Functions to Customize Your Applications

Now let’s look at a function that performs exactly the same operation, but does so with much less code. This function is provided for you in the Convention database from your download. You don’t have to add or remove spaces with this function because it simply checks and changes each character as it goes. Let’s see how it works.

Function CapFirstLetter(StrInput As String) 
Dim Mark As Integer, Char As String 

For i = 1 To Len(StrInput) 
  Char = Mid(StrInput, i, 1) 
  If Char = " " Then 
    Mark = i 
  ElseIf i = Mark + 1 Then 
    Mid(StrInput, i, 1) = UCase(Mid(StrInput, i, 1)) 
  Else 
    Mid(StrInput, i, 1) = LCase(Mid(StrInput, i, 1)) 
  End If 
Next i 
CapFirstLetter = StrInput 

End Function 

This entire procedure uses only ...

Get Access 2002 Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.