Disable control(s) on subform

B

Brian

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?
 
S

Steve Schapel

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")
 
N

Nikos Yannacopoulos

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
 
B

Brian

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")
 

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