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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo boxes

Status
Not open for further replies.

DirtDawg

IS-IT--Management
Apr 17, 2002
218
JP
Hello,

I have a question not sure if it can be done in VBA. If I have one combo box that has a list. If I select one selection from it, and then can I have it look at the information in another table. example

combo1 has a list of cpu makers
when selecting a computer
it opens combo2 with a list models.

this is all on the same form
 
Sure you can:

I assume you have 2 tables.

tblMaker and tblModel with the field MakerID as the Primary Key in tblMaker and the Foreign Key in tblModel


Set the row source for cmbMaker to

SELECT MakerID, MakerName FROM tblMaker;

and the row source to cmbModel to

SELECT ModelID, ModelName FROM tblModel WHERE MakerID=[Forms]![frmCPUList]![cmbMaker];

then on the AfterUpdate event of cmbMaker add the code

Me.cmbModel.requery

HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
On your first combo write code like this for the OnChange event:
Code:
 Combo2.RowSource = "SELECT ModelName FROM tblCPUModel WHERE CPUManufacturer = '" & Combo1.Value & "';"

This is assuming you have 2 tables
tblManufacturer that contains a list of CPU Manufacturers
Manufacturer
IBM
Commodore
Tandem

and
tblCPUModel that contains a list like this
Manufacturer Model
IBM 286
IBM 386
IBM 360
Tandem TXP
Tandem VLX

Hopefully you'd design your database better than that !!

Hope that helps.
 
I keep getting an error now
the record sorce selectmodelid,voyagefrom tblmodel where makerid= specified on this form does not exist

any ideas
The table does exist
 
I am trying to design it better
I would like one combo box for the makers
and one combo box each for the models

example
1combo showing
compaq
ibm
dell

the 2combo depending on what was selected
if compaq selected would only show compaq
if ibm selected then only ibm
if dell selected then only dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top