Solved

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

Posted on 2011-02-28
3
339 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 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

733 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