I have a public Function I use for Capitalizing the first Character in each work in a text box:
Function CapitalizeFirst(Str)
Dim Counter, StrLen As Integer
Counter = 1
StrLen = Len(Trim(Str))
CapitalizeFirst = UCase(Mid(Str, 1, 1))
Do While Counter < StrLen
Counter = Counter + 1
If Mid(Str, Counter, 1) = "" Then
CapitalizeFirst = CapitalizeFirst & ""
Counter = Counter + 1
CapitalizeFirst = CapitalizeFirst & UCase(Mid(Str, Counter, 1))
Else
CapitalizeFirst = CapitalizeFirst & UCase(Str, Counter, 1)
End If
Loop
End Function
What I would like to do if possible, is assign each text box a "tag" that I want the CapitalizeFirst function to be used in. The "tag" is "Cap", but I don't know where or exactly how to call my Function. The above code is in a Module. The following is what I have tried unsuccessfully in a forms After_Update event. I am hoping to avoid putting it in each Text box After_Update event. Let me know if you can help, or if this is even possible. Hopefully I am on the right track, thanks.
Private Sub Form_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Cap" Then
If Not(IsNull(Me.ctl))Then
Me.ctl = CapitalizeFirst((Me.ctl))
Next ctl
End If
End If
End Sub
Function CapitalizeFirst(Str)
Dim Counter, StrLen As Integer
Counter = 1
StrLen = Len(Trim(Str))
CapitalizeFirst = UCase(Mid(Str, 1, 1))
Do While Counter < StrLen
Counter = Counter + 1
If Mid(Str, Counter, 1) = "" Then
CapitalizeFirst = CapitalizeFirst & ""
Counter = Counter + 1
CapitalizeFirst = CapitalizeFirst & UCase(Mid(Str, Counter, 1))
Else
CapitalizeFirst = CapitalizeFirst & UCase(Str, Counter, 1)
End If
Loop
End Function
What I would like to do if possible, is assign each text box a "tag" that I want the CapitalizeFirst function to be used in. The "tag" is "Cap", but I don't know where or exactly how to call my Function. The above code is in a Module. The following is what I have tried unsuccessfully in a forms After_Update event. I am hoping to avoid putting it in each Text box After_Update event. Let me know if you can help, or if this is even possible. Hopefully I am on the right track, thanks.
Private Sub Form_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Cap" Then
If Not(IsNull(Me.ctl))Then
Me.ctl = CapitalizeFirst((Me.ctl))
Next ctl
End If
End If
End Sub