Problem with accessing controls in subForms

Dembrey

Registered User.
Local time
Today, 21:10
Joined
Mar 6, 2002
Messages
65
Hi All,

Help with the following would be appreciated (Access97).

I have a 'generic' function that (attempts) to set the SpecialEffect property of all TextBoxes on the specified form. Problem is that the Forms that call this function contain a variable number of SubForms and I would like to set the SpecialEffect property of TextBoxes in the SubForms too. The code looks like this:

-----------------

Function UpdateSFX(Myform As Form, SFX As Integer)

Dim MyControl As Control, MySubControl As Control

For Each MyControl In MyForm.Controls

Select Case MyControl.ControlType
Case acTextBox
MyControl.SpecialEffect = SFX

Case acSubform
For Each MySubControl In MyControl.Controls
MySubControl.SpecialEffect = SFX
Next MySubControl

End Select

Next MyControl

End Function

-----------

This works fine for the 'Case acTextBox' clause but not for the 'Case acSubform' clause.

I tried explicity stating a subform as in:
'For Each MySubControl In Me.{MySubformName}.Controls'
in a separate function for a known form and it worked, so what am I doing wrong/ whats missing in the first case?

Many thanks.

[This message has been edited by Dembrey (edited 03-11-2002).]
 
Try this:

Function UpdateSFX(Myform As Form, SFX As Integer)

Dim MyControl As Control, MySubControl As Control

For Each MyControl In MyForm

Select Case MyControl.ControlType
Case acTextBox
MyControl.SpecialEffect = SFX

Case acSubform
For Each MySubControl In MyControl.Form
If MySubControl.ControlType = acTextBox Then
MySubControl.SpecialEffect = SFX
End If
Next MySubControl

End Select

Next MyControl

End Function

Does that do it?

Doug.
 
Doug you're a genius. Yes it does.

Many thanks.
 

Users who are viewing this thread

Back
Top Bottom