Looping through form controls and updating their properties

Howdy Folks,

After a bit of searching I can't quite find a clear answer so thought I would ask the question (probably again, so apologies).

I have written a function that is intending to loop through the controls on a form to replace apostrophes with a safe version to aid with dynamic sql production (the sql bit isn't important, just context)

so here is the function:

    Public Sub TextBoxQuotes(ByVal Parent As Object)
        Dim c As Control
        For Each c In Parent.Controls
            If c.HasChildren Then
                TextBoxQuotes(c)
            Else
                If TypeOf (c) Is TextBox Then
                    c.Text.Replace(Chr(39), Chr(96)) 'replace ' with `
                End If
            End If
        Next
    End Sub

Tracing through a run, the function is entered into and will step in correctly but the replace doesn't seem to do anything. I assume this is some schoolboy error on my part! I have tried ByRef and ByVal to no change and have wondered if i am somehow creating an instance of the control instead of actually updating the original.

Can anyone see why the replace isn't doing anything?

Any help would be appreciated
LVGICTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
The Replace method on a string actually returns a string rather than simply acting on the string itself. So you will need to change the line to:

     c.Text = c.Text.Replace(Chr(39), Chr(96))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimCotteeHead of Software ServicesCommented:
Hi LVGICT,

                    c.Text = c.Text.Replace(Chr(39), Chr(96)) 'replace ' with `

You are not assigning the result of the replace to anything.

Tim Cottee
LVGICTAuthor Commented:
AHAAA...

spot the fool (*raises hand*)

Many Thanks guys

not quite sure why i thought the replace would act on itself

Have split the points as you were within a miniute of each other so i feel its unfair to say one answered and the other didn't... hope that is ok
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.