By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

COMBO BOX...create with code

P: 98
Has anyone created a combo box from scratch with vba in access? I would like the AFTER UPDATE event to create a combo box and populate it with items dependent on what the user selects. I know how to populate programatically, but haven't figured out how to CREATE the combo box programatically. Thank you in advance!
Feb 8 '07 #1
Share this Question
Share on Google+
3 Replies


nico5038
Expert 2.5K+
P: 3,072
The easy way os to place the combobox and set the Visible property to False.
When the selection of the first combo has been made use:

Expand|Select|Wrap|Line Numbers
  1. if LEN(NZ(me.combo1)) > 0 then
  2.   Me.combo2.recordsource = "select X from tblY where ID=" & me.combo1
  3.   Me.combo2.visible = true
  4. else
  5.   Me.combo2.visible = false
  6. endif
  7.  
This will activate the second combo when a selection has been made.
Getting the idea ?

Nic;o)
Feb 8 '07 #2

ADezii
Expert 5K+
P: 8,638
Has anyone created a combo box from scratch with vba in access? I would like the AFTER UPDATE event to create a combo box and populate it with items dependent on what the user selects. I know how to populate programatically, but haven't figured out how to CREATE the combo box programatically. Thank you in advance!
What you are asking is impossible and I'll explain why.To create a variety of Controls you must use, oddly enough, the CreateControl Method.This Method is used in a Custom Wizard to create Controls in a Form or Report only. This Method can 'only' be used in Form or Report Design View so what you are requesting is not feasible. If you are still interested though, here goes the syntax:

Expand|Select|Wrap|Line Numbers
  1. Dim MyControl As Control
  2. Set MyControl = CreateControl("frmTest", acComboBox, acDetail, , "", 2880, 2880, 2000, 300)
  3.  
  4. Parameter Explanations
  5. __1 frmTest - name of the Form on which you want to create the Control.
  6. __2 acComboBox - intrinsic Constant identifying Type of Control to create.
  7. __3 acDetail - intrinsic Constant identifying the Section that will contain the new Control.
  8. __4  "" - name of the Parent Control (if none, empty string).
  9. __5 2880 - left offset from the Form in Twips (1 in. = 1440 Twips). - 2 in.
  10. __6 2880 - top offset from the Form in Twips (1 in. = 1440 Twips). - 2 in.
  11. __7 2000 - width of Control in Twips (approx. 1,4 in).
  12. __8  300 - heigth of the Control in Twips (approx. .21 in).
  13.  
  14. NOTE: To actually see this in action, place your Form in Design view, 
  15. replace frmTest with your Form Name, create a Public Function 
  16. Procedure, then run it from the Debug Window. Sorry that you asked this question?
Feb 9 '07 #3

P: 98
What you are asking is impossible and I'll explain why.To create a variety of Controls you must use, oddly enough, the CreateControl Method.This Method is used in a Custom Wizard to create Controls in a Form or Report only. This Method can 'only' be used in Form or Report Design View so what you are requesting is not feasible. If you are still interested though, here goes the syntax:

Expand|Select|Wrap|Line Numbers
  1. Dim MyControl As Control
  2. Set MyControl = CreateControl("frmTest", acComboBox, acDetail, , "", 2880, 2880, 2000, 300)
  3.  
  4. Parameter Explanations
  5. __1 frmTest - name of the Form on which you want to create the Control.
  6. __2 acComboBox - intrinsic Constant identifying Type of Control to create.
  7. __3 acDetail - intrinsic Constant identifying the Section that will contain the new Control.
  8. __4  "" - name of the Parent Control (if none, empty string).
  9. __5 2880 - left offset from the Form in Twips (1 in. = 1440 Twips). - 2 in.
  10. __6 2880 - top offset from the Form in Twips (1 in. = 1440 Twips). - 2 in.
  11. __7 2000 - width of Control in Twips (approx. 1,4 in).
  12. __8  300 - heigth of the Control in Twips (approx. .21 in).
  13.  
  14. NOTE: To actually see this in action, place your Form in Design view, 
  15. replace frmTest with your Form Name, create a Public Function 
  16. Procedure, then run it from the Debug Window. Sorry that you asked this question?

Thank you for all your help!
Feb 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.