Continuous Form - Dependent Combo
How to have a Continuous Form but with a Dependent Combo per Record
I came across an issue recently where I needed to have a Continuous Form but with a Dependant Combo.
Access doesn't do this as a combo contains the same recordset for each record or row.
In this example we have a list of Students that have a list of Options or Choices for the Subjects they have picked.
Each Subject has a set of Grades that can be achieved. These are different for each Subject.
|Applied Science||A Level|
I could create a combo with ALL grades but then a user may choose a Grade for a Subject that isn't correct.
My solution is to use a Textbox control over a ComboBox that displays the value and to requery the Combo when it is selected.
First create a Query that filters the Grades given the Subject choice.
You can do this by getting the value from a Form and using it as Query Criteria. This Tip explains how.
SELECT * FROM tblGrade WHERE Type=#
We need 3 controls:
- TextBox to store the chosen Grade [Grade]
- ComboBox to chose a Grade [cboGrade]
- TextBox to display the chosen Grade [txtGrade]
The First TextBox can remain hidden, just have it at the back.
The ComboBox can be filled with the above Query.
The second TextBox can be use a DLOOKUP to get the Grade value.
=Nz(DLookUp("Grade","tblGrade","GradeID=" & [Grade]),"")
I've stacked these to show each of them, layer these ontop of each other.
Now when the user selects the ComboBox Refresh it so the Query updates.
Private Sub cboGrade_GotFocus()
When a Grade has been chosen from the ComboBox set the Grade TextBox to the value of the ComboBox, then Save the Record and then set the Focus of the other TextBox so that it comes to the forefront.
Private Sub cboGrade_AfterUpdate()
Grade = cboGrade '.Column(1)
Me.Dirty = False 'DoCmd.RunCommand acCmdSaveRecord
This will now use the
DLOOKUP to get value and display it. It will appear as if the combo is showing it but it isn't.
By: Alex Hedley
Click here to sign up for more FREE tips