LVGICT
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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