Navigator02
New member
- Local time
- Today, 10:49
- Joined
- Mar 22, 2013
- Messages
- 3
Greetings,
New to the forum and have a question about updating my table when I use cascading combo boxes in my form.
What is happening is that my table is being populated by the xxxxID column vice from the xxxxName column that is being used from that specific table.
here is my visual basic code that I am using to determine what the subsequent combo box will display.
Option Compare Database
Option Explicit
Private Sub cboPlanktonID_AfterUpdate()
' Set the Family combo box to be limited by the selected Plankton Type
Me.cboFamilyID.RowSource = "SELECT tblFamily.FamilyID, tblFamily.FamilyName FROM tblFamily " & _
" WHERE OrderID = " & Nz(Me.cboPlanktonID) & _
" ORDER BY FamilyName"
Me.cboFamilyID = Null
EnableControls
End Sub
Private Sub cboFamilyID_AfterUpdate()
' Set the Organism combo box to be limited by the selected Family
Me.cboOrganismID.RowSource = "SELECT tblType.TypeID, tblType.TypeName FROM tblType " & _
" WHERE FamilyID = " & Nz(Me.cboFamilyID) & _
" ORDER BY TypeName"
Me.cboOrganismID = Null
EnableControls
End Sub
Private Sub cboOrganismID_AfterUpdate()
' Set the Species combo box to be limited by the selected Organism
Me.cboSpeciesID.RowSource = "SELECT tblSpecies.SpeciesID, tblSpecies.SpeciesName FROM tblSpecies " & _
" WHERE TypeID = " & Nz(Me.cboOrganismID) & _
" ORDER BY SpeciesName"
Me.cboSpeciesID = Null
EnableControls
End Sub
Private Sub EnableControls()
' Clear the combo boxes
If IsNull(Me.cboWaterbodyID) Then
Me.cboLocationID = Null
End If
If IsNull(Me.cboPlanktonID) Then
Me.cboFamilyID = Null
End If
If IsNull(Me.cboFamilyID) Then
Me.cboOrganismID = Null
End If
If IsNull(Me.cboOrganismID) Then
Me.cboSpeciesID = Null
End If
' Enable or disable combo boxes based on whether the combo box preceeding it has a value.
Me.cboLocationID.Enabled = (Not IsNull(Me.cboWaterbodyID))
Me.cboFamilyID.Enabled = (Not IsNull(Me.cboPlanktonID))
Me.cboOrganismID.Enabled = (Not IsNull(Me.cboFamilyID))
Me.cboSpeciesID.Enabled = (Not IsNull(Me.cboOrganismID))
End Sub
Private Sub cboWaterbodyID_AfterUpdate()
' Set the Sampling Location combo box to be limited by the selected Waterbody Type
Me.cboLocationID.RowSource = "SELECT tblLocation.LocationID, tblLocation.LocationName FROM tblLocation " & _
" WHERE WaterbodyID = " & Nz(Me.cboWaterbodyID) & _
" ORDER BY LocationName"
Me.cboLocationID = Null
EnableControls
End Sub
Private Sub Form_Load()
' When the form loads, enable/disable the combo boxes. Combo boxes are only enabled if the preceeding combo box has a value.
EnableControls
End Sub
Example of the Combo box Row Source is: SELECT [tblWaterbody].[WaterbodyID], [tblWaterbody].[WaterbodyName] FROM tblWaterbody;
My Control Source is PlanktonAnalysis.WaterbodyName
When I fill in the form with the data, The Waterbody name is visable for selection (example: I see "Lake Lillinonah" in the cascading combo box, But when I save the record in the PlanktonAnalysis Table I get a number in the WaterbodyName column vice the name of the waterbody
PlanktonAnalysisIDWaterbodyName172
311411511677118397104113
tblWaterbodyWaterbodyIDWaterbodyName2Ashland Pond3Bantam Lake4Crystal Lake5Gardner Lake6Hungerford Park Pond7Lake Lillinonah8Lower Bolton Lake9Middle Bolton Lake10Pocotopaug Lake11West Thompson Reservoir
Any help would be greatly appreciated
Thanks
Bruce g
New to the forum and have a question about updating my table when I use cascading combo boxes in my form.
What is happening is that my table is being populated by the xxxxID column vice from the xxxxName column that is being used from that specific table.
here is my visual basic code that I am using to determine what the subsequent combo box will display.
Option Compare Database
Option Explicit
Private Sub cboPlanktonID_AfterUpdate()
' Set the Family combo box to be limited by the selected Plankton Type
Me.cboFamilyID.RowSource = "SELECT tblFamily.FamilyID, tblFamily.FamilyName FROM tblFamily " & _
" WHERE OrderID = " & Nz(Me.cboPlanktonID) & _
" ORDER BY FamilyName"
Me.cboFamilyID = Null
EnableControls
End Sub
Private Sub cboFamilyID_AfterUpdate()
' Set the Organism combo box to be limited by the selected Family
Me.cboOrganismID.RowSource = "SELECT tblType.TypeID, tblType.TypeName FROM tblType " & _
" WHERE FamilyID = " & Nz(Me.cboFamilyID) & _
" ORDER BY TypeName"
Me.cboOrganismID = Null
EnableControls
End Sub
Private Sub cboOrganismID_AfterUpdate()
' Set the Species combo box to be limited by the selected Organism
Me.cboSpeciesID.RowSource = "SELECT tblSpecies.SpeciesID, tblSpecies.SpeciesName FROM tblSpecies " & _
" WHERE TypeID = " & Nz(Me.cboOrganismID) & _
" ORDER BY SpeciesName"
Me.cboSpeciesID = Null
EnableControls
End Sub
Private Sub EnableControls()
' Clear the combo boxes
If IsNull(Me.cboWaterbodyID) Then
Me.cboLocationID = Null
End If
If IsNull(Me.cboPlanktonID) Then
Me.cboFamilyID = Null
End If
If IsNull(Me.cboFamilyID) Then
Me.cboOrganismID = Null
End If
If IsNull(Me.cboOrganismID) Then
Me.cboSpeciesID = Null
End If
' Enable or disable combo boxes based on whether the combo box preceeding it has a value.
Me.cboLocationID.Enabled = (Not IsNull(Me.cboWaterbodyID))
Me.cboFamilyID.Enabled = (Not IsNull(Me.cboPlanktonID))
Me.cboOrganismID.Enabled = (Not IsNull(Me.cboFamilyID))
Me.cboSpeciesID.Enabled = (Not IsNull(Me.cboOrganismID))
End Sub
Private Sub cboWaterbodyID_AfterUpdate()
' Set the Sampling Location combo box to be limited by the selected Waterbody Type
Me.cboLocationID.RowSource = "SELECT tblLocation.LocationID, tblLocation.LocationName FROM tblLocation " & _
" WHERE WaterbodyID = " & Nz(Me.cboWaterbodyID) & _
" ORDER BY LocationName"
Me.cboLocationID = Null
EnableControls
End Sub
Private Sub Form_Load()
' When the form loads, enable/disable the combo boxes. Combo boxes are only enabled if the preceeding combo box has a value.
EnableControls
End Sub
Example of the Combo box Row Source is: SELECT [tblWaterbody].[WaterbodyID], [tblWaterbody].[WaterbodyName] FROM tblWaterbody;
My Control Source is PlanktonAnalysis.WaterbodyName
When I fill in the form with the data, The Waterbody name is visable for selection (example: I see "Lake Lillinonah" in the cascading combo box, But when I save the record in the PlanktonAnalysis Table I get a number in the WaterbodyName column vice the name of the waterbody
PlanktonAnalysisIDWaterbodyName172
311411511677118397104113
tblWaterbodyWaterbodyIDWaterbodyName2Ashland Pond3Bantam Lake4Crystal Lake5Gardner Lake6Hungerford Park Pond7Lake Lillinonah8Lower Bolton Lake9Middle Bolton Lake10Pocotopaug Lake11West Thompson Reservoir
Any help would be greatly appreciated
Thanks
Bruce g