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

Capitalization of First Letter

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Is there a way I can put the code in a global function to capitalize the first letter of all fields but not say email fields.

Code:
Private Sub LastName_AfterUpdate()
LastName = StrConv(LastName, vbProperCase)
End Sub
 
Code:
Public Function upperControl()
  Dim ctrl As Access.Control
  Set ctrl = Me.ActiveControl
  If Not Trim(ctrl & " ") = "" Then
    ctrl = StrConv(ctrl, vbProperCase)
  End If
End Function

Hilite each control and in its lost focus event propery
=upperControl()
 
I receive an error code:

Invalid use of Me keyword.

This code is being added to a subform
 
How are ya primagic . . .


Try:
Code:
[blue]Set ctrl = Screen.ActiveControl[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
primagic,

Did you try AceMan's code? Or did you resolve the earlier error?

To use the same code from MajP without the error, you may have to do a little more. Did you put the code in the Form's VBA module, or did you put it in a standard module? If a separate module, it would have to be different.

So, here's a reworking of mine that might work... maybe?
Code:
Private Sub TestFormCode()
    Dim ctl As Control
    Dim frm As Form

    Set frm = Forms("frmMyForm")
    Set ctl = frm.ActiveControl

    If Not Trim(ctl & " ") = "" Then
        ctl = StrConv(ctl, vbProperCase)
    End If

    Set ctl = Nothing
    Set frm = Nothing
    db.Close
    Set db = Nothing
End Sub

However, you'll probably need to refer to the subform as your Form object in the code in this post. To find the proper way of doing that (I rarely have needed to, and therefore don't remember off hand), refer to this link:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top