populate text boxes bsaed on combo box

B

Brad Reichert

I've posted this before but thought I'd try and explain it a bit better.

I've got a form that has controls to 2 tables. The PC table which contains
PC inventory info. PC serial model, CPU, Memory, etc. The other field is
the PC Models table which contains the default values for each specific PC
model. When a PC is model is selected in the combo box, I'd like the text
boxes (linked to the PC table) to be populated based on the default values
in the PC models table. Can this be done and how? I'm an access newbie.

Thanks,

Brad
 
R

Rick Brandt

Brad Reichert said:
I've posted this before but thought I'd try and explain it a bit better.

I've got a form that has controls to 2 tables. The PC table which contains
PC inventory info. PC serial model, CPU, Memory, etc. The other field is
the PC Models table which contains the default values for each specific PC
model. When a PC is model is selected in the combo box, I'd like the text
boxes (linked to the PC table) to be populated based on the default values
in the PC models table. Can this be done and how? I'm an access newbie.

Include all of the additional data in your ComboBox as additional columns(they can be
hidden if you like). Then in the AfterUpdate event of the ComboBox run code similar
to...

Me!CPU = Me!ModelComboBox.Column(1)
Me!Memory = Me!ModelComboBox.Column(2)
etc..

The column numbering is zero-based so Column(0) is the left-most, followed by
Column(1), etc..
 
B

Brad Reichert

Rick Brandt said:
Include all of the additional data in your ComboBox as additional columns(they can be
hidden if you like). Then in the AfterUpdate event of the ComboBox run code similar
to...

Me!CPU = Me!ModelComboBox.Column(1)
Me!Memory = Me!ModelComboBox.Column(2)
etc..

The column numbering is zero-based so Column(0) is the left-most, followed by
Column(1), etc..

Ok, so in the combo box I include model, CPU, Memory, etc from the PC Models
(defaults) table. Then I enter that code in the afterupdate field where CPU
is the text box containing CPU info in he PCs (inventory) table and where
ModelComboBox is the name of the combo box we are coding. Is that all
right?

Thanks,

Brad
 
R

Rick Brandt

Brad Reichert said:
Ok, so in the combo box I include model, CPU, Memory, etc from the PC Models
(defaults) table. Then I enter that code in the afterupdate field where CPU
is the text box containing CPU info in he PCs (inventory) table and where
ModelComboBox is the name of the combo box we are coding. Is that all
right?

Well, you're right except for the AfterUpdate "field" bit.

You go to that event property and press on the build button to the right, choose
"Code Builder" from the choices, and then enter the code into the resulting Code
Module window.
 
B

Brad Reichert

Awesome. That worked...now how do I hide the other values in the combo box?
The only option I see is hide the key field.

Thanks,

Brad
 
R

Rick Brandt

Brad Reichert said:
Awesome. That worked...now how do I hide the other values in the combo box?
The only option I see is hide the key field.

Set the ColumnWidths property. The widths are separated in the box by
semicolons. Just use zero for the columns you don't want to see.

1.25";0";0";0"
 
B

Brad Reichert

Ok. I can get everything to work as long as there are no spaces in the
names. Here is what I have:
Private Sub PCModels_AfterUpdate()
Me!CPU = Me!PCModels.Column(1)
Me!Memory = Me!PCModels.Column(2)
Me!Hard_Drive = Me!PCModels.Column(3)
Me!Sound_Card = Me!PCModels.Column(4)
Me!Video_Card = Me!PCModels.Column(5)
Me!CDROM = Me!PCModels.Column(6)
Me!CDRW = Me!PCModels.Column(7)
End Sub

Columns 3, 4, and 5 don't work. How can I get them to work?

Thanks,

Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top