changing text

shutzy

Registered User.
Local time
Today, 08:08
Joined
Sep 14, 2011
Messages
775
i want to change text in txt boxes. when a new customer is being created we are too lazy to put uppercase in. so i want to change the text so the first letter is uppercase. i have used this on every event and it doesnt change a thing.

PHP:
Private Sub txtTown_AfterUpdate()
LResult = StrConv("TECH ON THE NET", 3)
End Sub
Private Sub txtPostcode_AfterUpdate()
LResult = StrConv([txtPostcode], 1)
End Sub
Private Sub txtStreet_AfterUpdate()
LResult = StrConv([txtStreet], 3)
End Sub
Private Sub txtFirstName_BeforeUpdate()
LResult = StrConv([txtFirstName], 3)
End Sub

i have this at the top
PHP:
Option Compare Database
Option Explicit
Dim LResult As String
Dim LResponse As Integer

what is wrong?
 
I would probably use a simple function, something along the lines of:

Code:
Private Function CapitalizeFirstLetter (currentControl as Control)

currentControl = UCase(Left(currentControl, 1)) & LCase(Mid(currentControl, 2))

End function

(Note: you should put in some error handling, and you should make it public (rather than private) if you want to use it on different forms too)

Then on the AfterUpdate event for the relevant control (in this example, your txtTown control):

Code:
=CapitalizeFirstLetter([txtTown])
 
ive never delt with fuction only sub. could you help me put a function in if it is different to sub. also where do i put the function. on what event etc.
 
Else, you may correct your code by assigning value of LResult to your text box, something like this:

Private Sub Test_AfterUpdate()
Dim LResult As String

LResult = StrConv([Test], 3)
Test = LResult

End Sub
 
Functions and subs are very similar. The main difference is that a function can return a value, whereas a sub does not.
The other difference is that a function can be called using "=FunctionName"... which is why I used a function above.

You can place the function in the same place as you would place a sub e.g. the form's module.
Then open your form in layout or design mode.
Select the control you want to use the function with. In this example, click on the text box 'txtTown'
If the Property Sheet is not open, press F4 to open it
Click on the Event Tab
In the After Update event, write: =CapitalizeFirstLetter([txtTown])

Now reopen the form and it should work.

BTW: StrConvert works fine if you want to capitalize the letter of EVERY word in the string. But if you only want to capitalize the first letter of the first word, you need to use Ucase and Lcase.
 
thanks all. the post by mahenkj2 work as i wanted it to. good insight to functions also
 

Users who are viewing this thread

Back
Top Bottom