Solved Refering to controls in subform

mafhobb

Registered User.
Local time
Today, 12:38
Joined
Feb 28, 2006
Messages
1,249
I have a main form (frmPropertyHistory) and a subform (frmMaterialsUseSubform). In the main form I have a combobox and an afterupdate event. The goal is to lock all controls in the subform when the combobox is updated.

This is my code:
Code:
    For Each ctl In Forms!frmPropertyHistory!frmMaterialsUseSubform.Controls
        Select Case ctl.ControlType                                                 'Select the controls to lock
            Case acTextBox                                                          'Textboxes
                ctl.Enabled = False
            Case acComboBox                                                         'ComboBoxes
                ctl.Enabled = False
            Case Else                                                               'Rest
                ctl.Enabled = False
        End Select
    Next

I get error 2465 in the first line: "Can't find the field "frmMaterialsUseSubform" referred to in your expression.

What am I doing wrong?

Thanks

Mafhobb
 
if your code is in the main form you refer to the controls in the subform as

subformname.form

e.g.

For Each ctl In frmMaterialsUseSubform.Form

note that not all controls have an enabled property (labels for example) so your code will fail if you do not exclude them
 
Like this:?

Code:
For Each ctl In frmMaterialsUseSubform.Form

Now I get "Error 424: Object Required" at that line

Thanks for the comment on the labels and such. I'll exclude them.
 
Last edited:
Code:
    Dim ctl As Control
    For Each ctl In Me!frmMaterialsUseSubform.Controls
        Select Case ctl.ControlType                                                 'Select the controls to lock
            Case acTextBox, acCombobox                                                           'Textboxes
                ctl.Enabled = False
        End Select
    Next
 
Code:
    Dim ctl As Control
    For Each ctl In Me!frmMaterialsUseSubform.Controls
        Select Case ctl.ControlType                                                 'Select the controls to lock
            Case acTextBox, acCombobox                                                           'Textboxes
                ctl.Enabled = False
        End Select
    Next
Hi arnelgp

This returns "error 2465. This db cannot find the field "frmMaterials........."
 
go in design view of your form.
click on the subform and see on the Property Sheet its Name.
 
agreed but me. is early bound (and uses intellisense) so typos are identified on compilation. me! is late bound so typos are not identified until runtime.
 

Users who are viewing this thread

Back
Top Bottom