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

Event procedure to call a function

Status
Not open for further replies.

krispi

MIS
May 16, 2002
281
GB
Can anyone help me with the following? I'm pretty much a VBA virgin so this is probably a very stupid question:
I have written a public function to convert a text string to propercase. However, when I try to write a generic event procedure which I can use to call the function from any number of different fields I keep getting errors. Can anyone help?

PS the procedure I had written which doesn't work was as follows:

Function Proper()
Dim ctl As Control
ctl = Screen.ActiveControl
ctl = ProperText(ctl)
End Function
 
Function Proper(ByVal myStr As String) As String
Proper = StrConv(myStr, 3)
End Function

To test from the debug window (Ctrl+G):

? proper("tHe Quick brown fox. he jUMPed over the lazy dog.")
The Quick Brown Fox. He Jumped Over The Lazy Dog.

'or

strSQL = "tHe Quick brown fox. he jUMPed over the lazy dog."
? proper(strSQL)
The Quick Brown Fox. He Jumped Over The Lazy Dog.
 
Cheers buddy that works great. However the real problem is how I call that function from the 'on change' event. I've tried various things including typing the name of the function, macros etc and I feel hugely dumb!!!!
 
The following seems to work in the AfterUpdate() event:

Private Sub Text229_AfterUpdate()
Me![Text229] = Proper(Me![Text229])
End Sub
 
FYI Krispi,

You were trying to pass a control object to a function that would need to be handling a string, unless you made it much more complex than it needed to be. You would need to use something like:

ctl.name = ProperText(ctl.name)

Steve King Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top