I have a form called frmPetsNew which contains two combo boxes
cboSpecies and cboBreed. The former contains categories such as Dog, Cat, Rabbit, Birds, Reptiles etc,
whilst the latter contains breeds relating to the selected species e.g. If Rabbit is selected then cboBreed should
show Angorra and any other breeds of rabbit. If Cat is selected then cboBreed should show Siamese etc.
I have the cboSpecies combo box working using the following code on its RowSource
Code:
Me.cboBreed.RowSource = "SELECT SpeciesRef FROM" & _
" tblBreeds WHERE SpeciesRef = " & _
Me.cboSpecies.Value & _
" ORDER BY SpeciesRef"
Me.cboBreed = Me.cboBreed.ItemData(0)
.
I understand that one needs to place some VBA code on the AfterUpdate event
of the cboSpecies object. The code currently reads as follows
When a Species is selected in cboSpecies, cboBreed is blank but seems to allow the depth of
the drop down list to relect the number of breeds for that species. For example
if you select Birds it shows space for the three bird breeds, whereas if you select
Dogs the cboBreed's drop down has a scroll bar to accomodate the many breeds of dogs
entered in that table (tblBreeds).
I have attached two screenshots showing the fields in both the tblSpecies and tblBreeds
tables.
Code:
Private Sub cboSpecies_AfterUpdate()
' Update the row source of the cboBreeds combo box
' when the user makes a selection in the cboSpecies
' combo box.
Me.cboBreed.RowSource = "SELECT SpeciesRef FROM" & _
" tblBreeds WHERE SpeciesRef = " & _
Me.cboSpecies.Value & _
" ORDER BY SpeciesRef"
Me.cboBreed = Me.cboBreed.ItemData(0)
End Sub
.
I would appreciate a perusal of my code and any advise that can be offered to resolve this matter, would.
be greatly appreciated.
I did try placing a cboBreed.Requery command, on the forms current event, and also
on the cboSpecies LostFocus event but to no avail. I presume that the bound column on each
combo box should be set to 1, which is the numerical reference field for each combo.
But of course cboBreed needs to show the names of the breeds - relative to that number reference. I did actually
have the cboBreeds showing the numbers of the numerical references but no names were shown.
The latest position is that if you close the form with say Dogs selected in cboSpecies, then upon opening
the form it shows the names of all the breeds of dog contained in the table. However if one then selects say
Cats then the correct number of entries are shown but with just the reference for the Cats category (number 1) showing.
If you then return to the Dogs category, as your selection, it shows the number 2 for each of the names of the dog breeds stored.
Regards
Cheyanne