Add items to combo box in Access VBA

Hi all.

I have a combo box (cmbType) that will have 2 values: Sample or Product

I have a second combo box (cmbStatus) that I want it to have certain values based on cmbType.

If cmbType.Value = "Sample" Then I want cmbStatus to have the following 2 values: Send via UPS or Send via FedEx

Otherwise if cmbType.Value = "Product" then I want cmbStatus to have the following 3 values: DHL, USPS or FedEx

How can I do this using VBA, I will be adding it to the "OnEnter" event of cmbStatus.

Thank you in advance!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
You would use the After update event of the first combo the set the VALUES of the second.

i.e. something like
If Me.combo1 = "sample" then
    Me.Combo2.RowSource = "Send via UPS;Send via FedEx"
End if

Make sure that you set the Combo2 Rowsource type to Value list


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sim1980Author Commented:
After reading your suggestion I did it a little different:

Me.Combo2.AddItem "Send via UPS"
Me.Combo2.AddItem "Send via FedEx"

Thank you!
To set it up with some rigor, you have a three tables

TblShipTypes, with a autonumber Long ShipTypeID and text(50)ShipType
Two entries
ShipTypeID    ShipType
1                      Sample
2                      Product

TblShippers with autonumber Long ShipperID and Text(75) ShipperName
Four entries
ShipperID          ShipperName
1                           FedEx
2                           UPS
3                           DHL
4                           USPS

TblShippingMethods with autonumber Long ShippingMethodID, Long ShipperID , and Long ShipTypeID
A bunch of entries
ShippingMethodID  ShipTypeID  ShipperID
1                                  1                      1
2                                  1                      2
3                                  2                      1
1                                  2                      3
1                                  2                      4

Your first combo's (cboShipTypes)  .rowsource is TblShipTypes
Your second combo's (cboShippers) .rowsource is "select * from TblShippingMethods where ShipTypeID = " & Me.cboShipTypes

In the AfterUpdate Event of cboShipTypes you put

"OnEnter" is the event that occurs when you enter a control -- and not what you want.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.