Disable control(s) on subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to disable a couple of controls (text boxes) on a subform based on the
content of a combo box on the main form. It could work either in the
MyComboBox_AfterUpdate or SubForm_Enter. However, I cannot get it to work
from either of these, nor in the Activate or GotFocus of the subform. The
only place I got it to work was in the Current event of the subform, but it
is overkill to have it there, since that event fires on each current record
on the subform. Here is what I tried:

MyComboBox_AfterUpdate
If MyComboBox = "ABC" Then
Forms!MySubForm!MyControl.Enabled = False
Else
Forms!MySubForm!MyControl.Enabled = True
End If
End Sub

What am I missing?
 
Brian,

You are referring to the subform as if it was a form. You need to do it
more like this...

If Me.MyComboBox = "ABC" Then
Me.MySubForm.Form!MyControl.Enabled = False
Else
Me.MySubForm.Form!MyControl.Enabled = True
End If

You could simplify this to...

Me.MySubForm.Form!MyControl.Enabled = (Me.MyComboBox <> "ABC")
 
Brian,

Wrong reference to the subform. Try:

MyComboBox_AfterUpdate
If MyComboBox = "ABC" Then
Me.MySubForm!MyControl.Enabled = False
Else
Me.MySubForm!MyControl.Enabled = True
End If
End Sub

i.e. the subform must be referenced as an object belonging to the main
form (with the Me. keyword, since the code is in the main form's module).

HTH,
Nikos
 
Bingo!

Thanks.

Steve Schapel said:
Brian,

You are referring to the subform as if it was a form. You need to do it
more like this...

If Me.MyComboBox = "ABC" Then
Me.MySubForm.Form!MyControl.Enabled = False
Else
Me.MySubForm.Form!MyControl.Enabled = True
End If

You could simplify this to...

Me.MySubForm.Form!MyControl.Enabled = (Me.MyComboBox <> "ABC")
 
Back
Top