Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dependent Combo Boxes

Access Howto:

Dependent Combo Boxes

by  Bullschmidt  Posted    (Edited  )
Have you ever wanted to have a second combo box (perhaps listing products) based on another combo box (perhaps listing companies)? Thus after the user chooses a company, he then sees only the products for that company in the second combo box.

For criteria in the 2nd combo box (and to get to the query design mode of the combo box click on the 3 dots just to the right of the combo box's RowSource property):
Like [Forms]![MyForm]![MyFirstComboBox]

And for the OnEnter property of the 2nd combo box:
=ctlRequery()

And in any module:
Public Function ctlRequery()
' Purpose: Use this in OnEnter property of a combobox that's based on another control
' that may have changed or based on records that may have changed
' since the form was first opened.

On Error GoTo Err_ctlRequery

' Dim var.
Dim ctl As Control

' Set var.
Set ctl = Screen.ActiveControl

' Requery control.
ctl.Requery

Exit Function

Err_ctlRequery:
Exit Function

End Function

For an example of dependent combo boxes you can download my sample invoices database currently at the link toward the bottom of http://www.bullschmidt.com/login.asp and then on the Invoices Dialog check out the Invoice # combo box which is based on the Rep # combo box.

J. Paul Schmidt, Freelance Access and ASP Developer
http://www.Bullschmidt.com/Login.asp - Database on the Web Demo
http://www.Bullschmidt.com/Access - Sample Access Invoices Database
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top