getting combo box to work in a subform

G

Guest

Hi all,

I have been working on this code for many hours but I cant get it right.
Hope somebody could help a desperate here. This is my problem.

I have 3 combo boxes in subform. The second combo box row source will depend
on the selection of the first as well as the third will depend on the second.
All works fine when opened as a main form but when it is being called as
subform, I get this error message:

You can't assign a value to this object:
*The object may be a control on a read-form only.
*The object maybe on a form that is on design view.
*The value may be too large for this field

And when I click "OK", I get another error message:

Run-time error '2450'

And it said that it can't find the form (tbl_damagescount) I wrote in a
macro expression or visual basic code.

I have a table named: tbl_Defects (source of 3 combo boxes' row source)
I have a subform named: tbl_damagescount > this is a form, just a bad naming
:)
I have a main form: frm_Main

In the first combo box, I have this statement on "after update" event to
generate the row source for second combo:

strSQL = "SELECT DISTINCT tbl_Defects.Defects_Category FROM tbl_Defects" & "
WHERE tbl_Defects.Location = '" & Forms!tbl_damagescount.Damage_Location &
"'"

Defects_Category.RowSource = strSQL

In the second, I also have this statement to generate row source for the
third combo:

strSQL = "SELECT DISTINCT tbl_Defects.Defects FROM tbl_Defects" & " WHERE
tbl_Defects.Defects_Category = '" & Forms!tbl_damagescount.Defects_Category &
"'"

Defects.RowSource = strSQL

I know I'm missing something to include the main form in the statements
since it worked perfectly when opened alone.

For "You can't assign a value to this object:..." error, I don't know know
what triggered this.

I'm very new to this, looking forward for your replies.

This is the link of the database.

http://www.vpineda.com/PKGQADB.mdb

Thank you very much.

vic.
 
M

Marshall Barton

Victor said:
I have been working on this code for many hours but I cant get it right.
Hope somebody could help a desperate here. This is my problem.

I have 3 combo boxes in subform. The second combo box row source will depend
on the selection of the first as well as the third will depend on the second.
All works fine when opened as a main form but when it is being called as
subform, I get this error message:

You can't assign a value to this object:
*The object may be a control on a read-form only.
*The object maybe on a form that is on design view.
*The value may be too large for this field

And when I click "OK", I get another error message:

Run-time error '2450'

And it said that it can't find the form (tbl_damagescount) I wrote in a
macro expression or visual basic code.

I have a table named: tbl_Defects (source of 3 combo boxes' row source)
I have a subform named: tbl_damagescount > this is a form, just a bad naming
:)
I have a main form: frm_Main

In the first combo box, I have this statement on "after update" event to
generate the row source for second combo:

strSQL = "SELECT DISTINCT tbl_Defects.Defects_Category FROM tbl_Defects" & "
WHERE tbl_Defects.Location = '" & Forms!tbl_damagescount.Damage_Location &
"'"

Defects_Category.RowSource = strSQL
[snip]


A subform does not exist in the Forms collection. Your
reference to it in the strSQL= lines will fail. Actually,
this is a good example of why you should use Me whenever
possible.

strSQL = "SELECT DISTINCT tbl_Defects.Defects_Category " _
& "FROM tbl_Defects " _
& "WHERE tbl_Defects.Location = '" _
& Me.Damage_Location & "'"
 

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