enable a combo box in one form based on input in another form

A

Angela

I'm a novice programmer and was hoping that someone could help me.

I have a combo box in form 1, and another combo box in form 2. Currently
the combo box in form 2 is NOT enabled.
This is what I'm trying to do: when the user selects "yes" in combo_box1 in
form 1, I want the combo_box2 in form 2 to be enabled. I tried using a
public variable to enable combo_box2 but as I move from one record to
another, the public variable is not updated.

If anyone has an answer or better method of how to activate combo_box2 (in
form 2) based on the selection of combo_box1 (in form 1), please let me know.
Thank you in advance.
 
P

pietlinden

I'm a novice programmer and was hoping that someone could help me.

I have a combo box in form 1, and another combo box in form 2.  Currently
the combo box in form 2 is NOT enabled.
This is what I'm trying to do: when the user selects "yes" in combo_box1 in
form 1, I want the combo_box2 in form 2 to be enabled.  I tried using a
public variable to enable combo_box2 but as I move from one record to
another, the public variable is not updated.

If anyone has an answer or better method of how to activate combo_box2 (in
form 2) based on the selection of combo_box1 (in form 1), please let me know.
 Thank you in advance.  

You don't need public variables. The two forms just have to be open.
Or the first form can open the second in the combo's AfterUpdate event

From form 1

Forms![frmSecondForm]![cboToEnable].Enabled=True
 
A

Angela

Thanks for the quick response.
I tried it but it didn't work. I got a runtime error that it couldn't find
the second form.
They are both subforms and are already open. I'm not sure what to do.

I'm a novice programmer and was hoping that someone could help me.

I have a combo box in form 1, and another combo box in form 2. Currently
the combo box in form 2 is NOT enabled.
This is what I'm trying to do: when the user selects "yes" in combo_box1 in
form 1, I want the combo_box2 in form 2 to be enabled. I tried using a
public variable to enable combo_box2 but as I move from one record to
another, the public variable is not updated.

If anyone has an answer or better method of how to activate combo_box2 (in
form 2) based on the selection of combo_box1 (in form 1), please let me know.
Thank you in advance.

You don't need public variables. The two forms just have to be open.
Or the first form can open the second in the combo's AfterUpdate event

From form 1

Forms![frmSecondForm]![cboToEnable].Enabled=True
.
 
J

John W. Vinson

They are both subforms and are already open. I'm not sure what to do.

The syntax for referencing a subform is a bit peculiar. The subform is NOT a
member of the Forms collection, which is why you're getting the error message.
The proper syntax uses the name of the Subform Control on the mainform - which
may or may not be the same as the name of the Form object within that control!

Try

Forms!mainform!subformcontrol.Form!combobox_2.Enabled = True
 
A

Angela

Thanks so much John. This worked at combo_box1's click event, however I got
a run time error (invalid reference) when I put the code in the form1's
current event.
The problem is that when I move from one record to the next, combo_box2 is
not updating accordingly. I thought the form1's current event will solve
this issue.
 
J

John W. Vinson

Thanks so much John. This worked at combo_box1's click event, however I got
a run time error (invalid reference) when I put the code in the form1's
current event.
The problem is that when I move from one record to the next, combo_box2 is
not updating accordingly. I thought the form1's current event will solve
this issue.

Please post your actual code. I wouldn't have used the combo's Click event
(but its AfterUpdate instead); and I would guess that the "enabledness" of the
second combo would depend on the presence or absence of a particular data
value in the table, not on the state of a display control on a form. More info
please!
 
A

Angela

Hi John,
Here's my code. I used the Click event of the first combo box (txrefdial)
to disable the second combo box (txdispdial).
Form 2 - referral is the main form that hold the first and second sub forms.

Then I tried using the first subform's current event to ensure that the
second combo box is enabled/disabled as the user moves from one record to
another.
Thanks for looking at this for me.

Private Sub txrefdial_Click()
dummytxtbox.SetFocus
If txrefdial.Value = "Yes" Then
Forms![Form 2 - referral]![3 - Consultation and Final
Disposition].Form![txdispdial].Enabled = False

ElseIf txrefdial.Value = "No" Then
Forms![Form 2 - referral]![3 - Consultation and Final
Disposition].Form![txdispdial].Enabled = True
End If
End Sub


Private Sub Form_Current()
dummytxtbox.SetFocus
If txrefdial.Value = "Yes" Then
Forms![Form 2 - referral]![3 - Consultation and Final
Disposition].Form![txdispdial].Enabled = False

ElseIf txrefdial.Value = "No" Then
Forms![Form 2 - referral]![3 - Consultation and Final
Disposition].Form![txdispdial].Enabled = True
End If
dummytxtbox.SetFocus
End Sub
 

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