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

ProperCase for the entire form 1

Status
Not open for further replies.

ironj32

Technical User
Dec 7, 2006
73
US
I have this for a txtBank, and it works fine

Private Sub bank_LostFocus()
Bank = StrConv(Bank, vbProperCase)
End Sub

is there a way to set this for every txtBox in the form with out having to write the Private Sub procedure for each control? maybe...

Private Sub Form(not sure what this would be)_LostFocus()
dim txtControl as string
txtControl = acActiveControl
txtControl = strConv(txtControl, vbProperCase)
end sub

maybe i have to use Me.Control or something?
I'm not really sure...pretty new at this.
Thanks for your input!


 
You can loop through the control collection in, say, the Before Update event, but you may run into difficulties where say, you have a field "NSW Engine Company", you will end up with "Nsw Engine Company", which may not be suitable.
 
I'm not sure if this is heading in the right direction???

Private Sub Form_load()

Dim ctl As control
For Each ctl In frm.Controls
If (ctl.ControlType = acTextBox) Then
StrConv(ctl, vbProperCase, 3) = True
End If
Next ctl
End Sub
 
I do not think that the form Load event is suitable. Try Before Update, to see if it suits:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
    If (ctl.ControlType = acTextBox) Then
        Me(ctl.Name) = StrConv(Me(ctl.Name), vbProperCase, 3)
    End If
Next ctl
End Sub
 
is there somewhere in there that i have to change to my own control name?
 
Not that I can see. Are you having problems? If so, please post the details.
 
i found the problem...i have a date field in there.


 
now i'd like to set it to change after each control box has lostfocus.
 
I am afraid you are back to adding code to each lost focus event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top