By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,484 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,484 IT Pros & Developers. It's quick & easy.

How to update a combo box depending on previous selection

P: 6
I'm making a database for a local school, and they need a form which lets them keep track of students assignments, and in turn the grades for that assignment.

So i have a form with all the basic controls on, what I want to know is, can I auto populate a combo box depending on what a user has already selected on a previous combo box.

So for example, I have a combo box called "Course", this is just a course present in the school, Computing for example.

Under that is a combo box called "Module", this is a part of the course. First i want that to only contain modules that are present on the already selected course (Programming for Computing, for example)

AND then (:-)) is another combo box under the module called "Assignment", I want that to contain only assignments relating to the Module selected previously.

Finally, there is a student combo box, which i want to only contain the students actually on the course previously selected.
May 5 '10 #1

✓ answered by Megalog

The concept you're looking for is called Cascading combo boxes.
There's a good article here just for that: Cascading Combo/List Boxes

Share this Question
Share on Google+
9 Replies


Megalog
Expert 100+
P: 378
The concept you're looking for is called Cascading combo boxes.
There's a good article here just for that: Cascading Combo/List Boxes
May 5 '10 #2

P: 6
Exactly what i wanted :-)

Thank's a lot
May 5 '10 #3

P: 6
Thought i'd post here instead of starting a new topic.

I've got the first two boxes done. My module combo box updates properly depending on the course selected.

But my assignment's dont. Im using pretty much the same code from the link posted by Megalog, but I try to test it and i get...

"Syntax Error (missing operator) in query expression '[Module] = Programming Fundamentals'"

Any idea what this means?

Thanks
May 5 '10 #4

Megalog
Expert 100+
P: 378
Please post the after update code for the Module combo box.
May 5 '10 #5

P: 6
The code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Module_AfterUpdate()
  2.   With Me![Assignment]
  3.     If IsNull(Me!Module) Then
  4.       .RowSource = ""
  5.     Else
  6.       .RowSource = "SELECT [AssignmentName] " & _
  7.                    "FROM Assignment " & _
  8.                    "WHERE [Module]=" & Me!Module
  9.     End If
  10.     Call .Requery
  11.   End With
  12. End Sub
May 5 '10 #6

Megalog
Expert 100+
P: 378
Is the Module field in AssignmentName numeric or text? If it's text, you need to change line 8 to be:

Expand|Select|Wrap|Line Numbers
  1.                    "WHERE [Module] = '" & Me!Module & "'"
May 5 '10 #7

P: 6
Just tried your suggestion, but they are both numeric so I got the data mistype error.
May 5 '10 #8

P: 6
EDIT: Deleted because I've solved it. :-)

Made it search for the ModuleID and the ModuleName, bound the assignment box to column 1 (the ID) then made it only display the actual ModuleName. :-)
May 6 '10 #9

NeoPa
Expert Mod 15k+
P: 31,186
A bit late now, but I expect Example Filtering on a Form would have helped you with this. It covers the formats of numeric, string and date literals.
May 6 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.