Recursive Function

  • Thread starter Thread starter ALESSANDRO Baraldi
  • Start date Start date
A

ALESSANDRO Baraldi

Hi.

I have a function that cicle all Controls on a Form and Formatt
the colors and effect on TextBox.
My problem born when on my Form i have SubForm/s
I think to build this function as a recursive one, but i
have some problem don't work....!

Function FormatControl(frm as Object)
dim ctr as control
With frm
for each ctr in .Controls
If Ctr.ControlType = acTextBox Then
'.....format
ElseIf Ctr.ControlType = acSubform Then
FormatControl(.Controls(ctr.Name))
End if
Next
End with
End Function

Is possible to to it like i think to have a better flexible function...?

Thanks in advace and good week end.
@Alex (Alessandro Baraldi)
 
This is the offending line
FormatControl(.Controls(ctr.Name))
In order to make the recursity work, you'll have to input
same type into the function.
Y're asking a form, then pass a form object shown below.
Replace above line by
FormatControl(ctr.Form)

and try again, ciao.

Krgrds,
Perry
 
Perry said:
This is the offending line
In order to make the recursity work, you'll have to input
same type into the function.
Y're asking a form, then pass a form object shown below.
Replace above line by
FormatControl(ctr.Form)

and try again, ciao.

Krgrds,
Perry


Hi Perry good Sunday...!
I understand but don't work again...!

I have an error "438-Property or Method not supported by object"
(italian translation)

This is the new one.

Function FormatControl(frm as Object)
dim ctr as control
With frm
for each ctr in .Controls
If Ctr.ControlType = acTextBox Then
ctr.ForeColor=vbred
ElseIf Ctr.ControlType = acSubform Then
FormatControl(ctr.Form)
End if
Next
End with
End Function

Thanks
 
A slight adjustment:

Function FormatControl(frm As Object)
Dim ctr As Object
For Each ctr In frm.Controls
If ctr.ControlType = acTextBox Then
ctr.BackColor = vbRed
ElseIf ctr.ControlType = acSubform Then
FormatControl (ctr.Form)
End If
Next
End Function
I've changed ForeColor to BackColor to see wether above snippet
had effect, and yes it did ...
Calling it from the click event of a commandbutton on parentform:

FormatControl Me

ciao again
Krgrds,
Perry
 
Just a really picky point.

You don't need the parentheses around ctr.Form when you're calling
FormatControl.

When you're invoking subroutines (or functions, when you don't call about
the returned value, such as in this case), either use

RoutineName Parameter1 [, Parameter2 [, Parameter3...]]

or

Call RoutineName (Parameter1 [, Parameter2 [, Parameter3...]])

In this case, it doesn't matter. However, if there was more than 1
parameter, having parentheses around the parameters and not using the Call
verb would result in an error.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Perry said:
A slight adjustment:

Function FormatControl(frm As Object)
Dim ctr As Object
For Each ctr In frm.Controls
If ctr.ControlType = acTextBox Then
ctr.BackColor = vbRed
ElseIf ctr.ControlType = acSubform Then
FormatControl (ctr.Form)
End If
Next
End Function
I've changed ForeColor to BackColor to see wether above snippet
had effect, and yes it did ...
Calling it from the click event of a commandbutton on parentform:

FormatControl Me

ciao again
Krgrds,
Perry
 
Thx for the detailed info.
I'm sure that Alessandro, like me, is aware of that :-)

Krgrds,
Perry

Douglas J. Steele said:
Just a really picky point.

You don't need the parentheses around ctr.Form when you're calling
FormatControl.

When you're invoking subroutines (or functions, when you don't call about
the returned value, such as in this case), either use

RoutineName Parameter1 [, Parameter2 [, Parameter3...]]

or

Call RoutineName (Parameter1 [, Parameter2 [, Parameter3...]])

In this case, it doesn't matter. However, if there was more than 1
parameter, having parentheses around the parameters and not using the Call
verb would result in an error.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
Thx for the detailed info.
I'm sure that Alessandro, like me, is aware of that :-)

Krgrds,
Perry


Yes of course it's a mistake, i'm usually use Call FunctionName
([Param1],[Param2]).

Wait for Reports strange mistake idea....

Thanks.
Ciao
 
Back
Top