Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

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.

Subjects
SubjectType
Applied ScienceA Level
ArtBTEC
......

Grades
GradeIDGradeType
1A*A Level
2AA Level
3BA Level
4CA Level
......
10Dist+BTEC
11DistBTEC
12MeritBTEC
14PassBTEC
......

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.

VBA
	Private Sub cboGrade_GotFocus()
		Me.Refresh
	End Sub
	

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
		txtGrade.SetFocus
	End Sub
	

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.

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP