field based on another field

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

Guest

Hello;

I have a subform with 4 different fields.
The value of the first field will determine the options that are available
in the last field.
The last field is a combo box based on a query. How do I get my query to
update based on the value entered in the first field?
If the answer is in code, please tell me where to put it as I am a first
time Access user.

Thanks so much,
G Riff
 
Griff said:
I have a subform with 4 different fields.
The value of the first field will determine the options that are available
in the last field.
The last field is a combo box based on a query. How do I get my query to
update based on the value entered in the first field?

Just for the Record: Tables and Queries have Fields. Forms and Reports
display Field (or Calculated) values in Controls; Text and Combo Boxes are
Controls.

To answer this specific question, you can refer to the first Control in the
query you use for RowSource of the Combo Box, and you can Requery the
ComboBox in the AfterUpdate event of the first Control.

Me!NameOfYourComboBox.Requery
 
Hello;

I have a subform with 4 different fields.

ummm... nitpick. You have a Table with four fields (or maybe more);
you have a subform based on that table with four Controls.
The value of the first field will determine the options that are available
in the last field.
The last field is a combo box based on a query. How do I get my query to
update based on the value entered in the first field?
If the answer is in code, please tell me where to put it as I am a first
time Access user.

You need to base the combo on a Query which references the first
control.

Let's say your main form is named MyForm, and on it there is a Subform
Control named subMySub (note that the Name property of the subform
control, the box on the mainform, is what's important; it might be
different from the name of the Form within that control). On the form
in subMySub there's a textbox txtFirst and a combo box named
cboFourth.

Set cboFourth's Row Source property to a query using

=Forms!MyForm!subMySub.Form!txtFirst

as a criterion to limit the rows in the combo box to those matching
the selected value in txtFirst.

You need one other thing: open the subform in design view, and view
txtFirst's properties. On the Events tab find the AfterUpdate event.
Click the ... icon, invoke Code Builder, and add one line to the two
Access will give you:

Private Sub txtFirst_AfterUpdate()
Me!cboFourth.Requery
End Sub


John W. Vinson[MVP]
 
Back
Top