uppercase first character

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have tried to create a function to make the first letter of user-input in
a textbox uppercase, if it is not already so.
The code I wrote is really very stupid:

Public Function FirstUp(s As String) As String
If Len(s) > 0 Then
FirstUp = UCase(Left(s, 1)) + Mid(s, 2)
Else
FirstUp = s
End If
End Function

Now, I thought that when I put a call to this function in for example the
event After Update of a textbox Dopeling like
After Update ...... = FirstUp ( [Dopeling] )
that input as "egbert" would be converted to "Egbert".
But nothing happens, how come?

Thanks for any help,

Greetings, Menne
 
Menne said:
Hello,

I have tried to create a function to make the first letter of
user-input in a textbox uppercase, if it is not already so.
The code I wrote is really very stupid:

Public Function FirstUp(s As String) As String
If Len(s) > 0 Then
FirstUp = UCase(Left(s, 1)) + Mid(s, 2)
Else
FirstUp = s
End If
End Function

Now, I thought that when I put a call to this function in for example
the event After Update of a textbox Dopeling like
After Update ...... = FirstUp ( [Dopeling] )
that input as "egbert" would be converted to "Egbert".
But nothing happens, how come?

Thanks for any help,

Greetings, Menne

The function will return the "upcased" value, but won't assign it to
anything. You could use this function:

'----- start of code -----
Public Function FirstUp()

Dim s As String

With Screen.ActiveControl
s = .Value & vbNullString
If Len(s) > 0 Then
s = UCase(Left$(s, 1)) & Mid$(s, 2)
.Value = s
End If
End With

End Function
'----- end of code -----

And then you wouldn't need to pass the control or its value to the
function; just write

=FirstUp()

in the control's AfterUpdate event property.
 
Back
Top