I am making a form to enter User Name information and I'm using some Capitalization code that I got from this site years ago. (quite handy too... kudos to the author... I have no clue who it was - wasn't me though) Anyway, usually I don't have any problem using this code. But that's because normally I write the code after every field_onExit event that I wish to capitalize. So normally it's written several times on every form. But I'm learning more and more on vba coding and recently have learned to write my own sub routines. But passing this controlname to my sub is driving me crazy. It's always passing the value of the control and not the controlname. I've seen this same problem posted on other posts here, and I've tried all their recommendations but still no luck. Here is what I'm working with:
I call the routine like this...
I've changed the call line from:
Call capcode(ctl,pnx)
to
capcode ctl, pnx
because of another post I read saying that it's helps to keep the routine from reading the value vs. the control name.
Still doesn't work... any help would be greatly appreciated.
~Snay
Code:
Sub capcode(MyControl As Control, MyString As String)
Dim Temp$, c$, OldC$, I As Integer
If IsNull(MyString) Then
Exit Sub
Else
Temp$ = CStr(LCase(MyString))
[COLOR=green]' Initialize OldC$ to a single space because first[/color]
[COLOR=green]' letter needs to be capitalized but has no preceding letter.[/color]
OldC$ = " "
For I = 1 To Len(Temp$)
c$ = Mid$(Temp$, I, 1)
If c$ >= "a" And c$ <= "z" And _
(OldC$ < "a" Or OldC$ > "z") Then
Mid$(Temp$, I, 1) = UCase$(c$)
End If
OldC$ = c$
Next I
End If
With MyControl
.Value = Temp$
End With
End Sub
I call the routine like this...
Code:
Private Sub FN_BeforeUpdate(Cancel As Integer)
Dim pnx As String [COLOR=green]'name to pass[/color]
pnx = FN.Value
Dim ctl As Control [COLOR=green]'control to pass[/color]
Set ctl = Forms!NMEMfrm!FN
capcode ctl, pnx
End Sub
I've changed the call line from:
Call capcode(ctl,pnx)
to
capcode ctl, pnx
because of another post I read saying that it's helps to keep the routine from reading the value vs. the control name.
Still doesn't work... any help would be greatly appreciated.
~Snay