Iterating subform on Load/Open gives error

M

Marcus

Hi there,
using Access 2003 I'd like to give users the opportunity to change
application font size on form's objects.

To do so I've set up on the menubar a font size option.

When font size is changed I need to iterate all objects on forms and change
font size.

I've set up a public function that iterates all objects in the forms
collection and changes font size, and it works for main forms.

When trying to use the same function in a recursive way to modify subforms I
get a runtime error 2450 ".... can't find the form 'form_name' refrred to in
a macro expressione or visual basic..."

here's the code:

'*********************** VBCODE

Public Function setFontSize(fntSize As Integer)
Dim Objform As Form

If globalFontSize <> fntSize Then 'changed fontsize
globalFontSize = fntSize
For Each Objform In Application.Forms 'iterate the Forms collection
setFormAttributes(Objform.Name) 'call function to change
fontsize
Next
End If

End Function


Public Function setFormAttributes(frmName As String)
Dim ctl As Control

For Each ctl In Forms(frmName).Controls 'iterate object collection
'<<<<<<<< offending instruction
Select Case ctl.ControlType
Case acComboBox, acCommandButton, acLabel, acListBox, acListBox,
acTextBox, acToggleButton 'capable objects
ctl.FontSize = globalFontSize
Case acSubform
setFormAttributes (ctl.Form.Name) 'recurse here into subform
End Select
Next

End Function

'*********************** END VBCODE

Can anyone solve this problem?
 
G

Guest

When you are itterating through the form's controls, you need to test to see
if it is a subform control. The you would have to interate through the
controls of the sourceobject of the subform control. The syntax is going to
be something like:

Forms!FormName!SubFormControlName.Form!Controls("ControlName")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top