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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help calling a Public function using a "Tag" 1

Status
Not open for further replies.

ImStuk

Technical User
Feb 20, 2003
62
US
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) = &quot;&quot; Then
CapitalizeFirst = CapitalizeFirst & &quot;&quot;
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 &quot;tag&quot; that I want the CapitalizeFirst function to be used in. The &quot;tag&quot; is &quot;Cap&quot;, 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 = &quot;Cap&quot; Then
If Not(IsNull(Me.ctl))Then
Me.ctl = CapitalizeFirst((Me.ctl))
Next ctl
End If
End If
End Sub
 
Use the Form_BeforeUpdate event. By the time the Form_AfterUpdate event fires, it's too late to make any changes to the current record. Otherwise, your approach is sound.
 
Oops! Thanks a lot for your help. After puting it in the After_Update Event and then tinkering a little...ie...getting rid of the &quot;Me&quot; in Me.ctl, and placing the Next ctl after the &quot;If's&quot;...IT WORKS GREAT! Thanks alot...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top