Basing one combo box on another

B

Bel

I'm having trouble creating a combo box that limits its list based on the
selection made in another combo box when using a subform. When I run the
subform by it self the code below runs great. My values for the combo box2
are limited based on the selection made in the combo box1. The problem is
when I access the form containing the combo boxes as a subform in another
form. After I make my selection in combo box1, I'm prompt to enter the value
that is to be used to limit the list in combo box2. Once I manually type the
value, combo box2 list of values is based on what I type NOT the value
selected in combo box1. Being prompt to enter a value defeats the value of
basing the combo box2 on combo box1. It appears that the value select in
combo box1 is not retained.

AfterUpdate:
Me.cboBox2 = Null
Me.cboBox2.Requery
Me.cboBox2 = Me.cboBox2.ItemData(0)
 
R

Ron2006

What we cannot see is the query that you are using for the datasource
for cboBox2. That is where the problem is. It should be a query that
has somethink like the following as the criteria.

Forms![name of form of cboBox1]![cboBox1]

If you are being asked to "enter" the criteria, that means that the
code cannot resolve the "location/existence" of the field you are
using as criteria as opposed to the value that is in the field.

If the code knew WHERE the criteria was it would use the value there,
even if the value was Null.

Ron
 
B

Bel

You are absolutely correct. The code that I used initially was..........
[Forms]![SubForm1]![cboBox1]. This worked great when I ran the form
SubForm1 but the problem I had was when I embeded SubForm1 in another form -
Form1. That's when I would get prompted to enter data. I think that this
occurred for the reason you stated in your response - the code could not
resolve the "location/existence" of the field. So I changed my query to......
[Forms]![Form1]![SubForm1]![cboBox1]. It works.

Thanks,

Bel
 

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