?
Solved

how to update a combo box based off values in another combo box?

Posted on 2011-02-28
3
Medium Priority
?
341 Views
Last Modified: 2013-11-28
I am trying to make selecting information easier on my form so I'd like to have combo boxes that update after a selection has been made.

I have a combo box that displays names of audits. The row source has this query in it:
SELECT [tbl_Audit].[Audit_ID], [tbl_Audit].[Audit_Name] FROM tbl_Audit ORDER BY [Audit_Name];

I want a second combo box to be based off the tbl_audit.audit_id that a user selects. I want to be able to show
SELECT tbl_observation.obs_id FROM tbl_observation, tbl_audit WHERE tbl_observation.audit_ID = the value that the user selected from the combo box above

I was thinking of whether this could be done just using the after updates or before update spots in the Properties boxes or if this had to be done with VB?
0
Comment
Question by:jtovar3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 2000 total points
ID: 35002156
This technique is called Cascading Comboboxes. It does require using VBA. There is a great tutorial here:
http://www.fontstuff.com/access/acctut10.htm

You will need to use code in the After Update event of the first combo box. You will also need to put code into the form's On Current event so that the correct list of choices is shown for previously entered data.

HTH,

pT72
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 35002258
<Assuming that AuditID is stored as a number field (not text field, like in the above website) >

Private Sub Combo1_AfterUpdate()
If IsNull(Combo1) = False Then
    Combo2.RowSource = "SELECT tbl_observation.obs_id FROM tbl_observation, tbl_audit WHERE tbl_observation.audit_ID = " & Combo1
Else
    Combo2.RowSource = "SELECT tbl_observation.obs_id FROM tbl_observation, tbl_audit"
End If
End Sub

Private Sub Form_OnCurrent()
If IsNull(Combo1) = False Then
    Combo2.RowSource = "SELECT tbl_observation.obs_id FROM tbl_observation, tbl_audit WHERE tbl_observation.audit_ID = " & Combo1
Else
    Combo2.RowSource = "SELECT tbl_observation.obs_id FROM tbl_observation, tbl_audit"
End If
End Sub

Open in new window


If AuditID was stored as text in the underlying table, you'd need to surround its value with apostrophes.

HTH,
pT72
0
 

Author Closing Comment

by:jtovar3
ID: 35022181
PERFECT!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question