Abdullah
07-07-2011, 12:02 PM
Hello,
I am working to put together a database, it's still early in the process, but I am hitting a snag.
As part of it, I have a table called tblobservations, a sample of it's data is below:
ID Component Condition
1 Window Sill
2 Window Head
3 Window Stained
4 Balcony Flashing
5 Vent Seam
6 Vent Damage
I am trying to achieve a form with 2 combo boxes, where you'll choose a component from combo box 1, and that selection will then influence the selections available in combo box 2.
Currently, I have combo box 1 named Component and in it's property sheet under Data - ROW Source, I have;
SELECT DISTINCT [tblconditions].[component], [tblconditions].[component] FROM tblconditions;
Pardon the use of VBA tags.
Combo box 1 is working, the drop down gives the 3 options, Window, Balcony, Vent (no duplicate components appear in drop down).
I believe that the second part of it, requires Combo box 1 to have an [Event Procedure] in the Event tab - After Update line. That is where I'm having trouble.
I was given an example, but am not sure it actually works. It has been changed only in regard to the table/combo designations, so that it would fit my project.
Option Compare Database
Option Explicit
Private Sub ComboComponent_AfterUpdate()
ComboCondition.RowSource = "SELECT tblobservations.condition " & _
"FROM tblobservations" & _
"WHERE tblobservations.condition = '" & ComboComponent.Value & "' " &_
"ORDER BY tblobservations.condition;"
End Sub
The problem is I keep getting errors with the VB code, or nothing happens at all. The condition (Combo box 2) remains blank in my form regardless of my selection in Combo box 1.
Any help, either getting the code to work by telling combo box 2 which selection was made, or another method to achieve my goal would be greatly appreciated.
I am working to put together a database, it's still early in the process, but I am hitting a snag.
As part of it, I have a table called tblobservations, a sample of it's data is below:
ID Component Condition
1 Window Sill
2 Window Head
3 Window Stained
4 Balcony Flashing
5 Vent Seam
6 Vent Damage
I am trying to achieve a form with 2 combo boxes, where you'll choose a component from combo box 1, and that selection will then influence the selections available in combo box 2.
Currently, I have combo box 1 named Component and in it's property sheet under Data - ROW Source, I have;
SELECT DISTINCT [tblconditions].[component], [tblconditions].[component] FROM tblconditions;
Pardon the use of VBA tags.
Combo box 1 is working, the drop down gives the 3 options, Window, Balcony, Vent (no duplicate components appear in drop down).
I believe that the second part of it, requires Combo box 1 to have an [Event Procedure] in the Event tab - After Update line. That is where I'm having trouble.
I was given an example, but am not sure it actually works. It has been changed only in regard to the table/combo designations, so that it would fit my project.
Option Compare Database
Option Explicit
Private Sub ComboComponent_AfterUpdate()
ComboCondition.RowSource = "SELECT tblobservations.condition " & _
"FROM tblobservations" & _
"WHERE tblobservations.condition = '" & ComboComponent.Value & "' " &_
"ORDER BY tblobservations.condition;"
End Sub
The problem is I keep getting errors with the VB code, or nothing happens at all. The condition (Combo box 2) remains blank in my form regardless of my selection in Combo box 1.
Any help, either getting the code to work by telling combo box 2 which selection was made, or another method to achieve my goal would be greatly appreciated.