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!
COMBO BOX...create with code
Collapse
X
-
Tags: None
-
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:
This will activate the second combo when a selection has been made.Code:if LEN(NZ(me.combo1)) > 0 then Me.combo2.recordsource = "select X from tblY where ID=" & me.combo1 Me.combo2.visible = true else Me.combo2.visible = false endif
Getting the idea ?
Nic;o) -
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:Originally posted by ineedahelpHas 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!
Code:Dim MyControl As Control Set MyControl = CreateControl("frmTest", acComboBox, acDetail, , "", 2880, 2880, 2000, 300) Parameter Explanations __1 frmTest - name of the Form on which you want to create the Control. __2 acComboBox - intrinsic Constant identifying Type of Control to create. __3 acDetail - intrinsic Constant identifying the Section that will contain the new Control. __4 "" - name of the Parent Control (if none, empty string). __5 2880 - left offset from the Form in Twips (1 in. = 1440 Twips). - 2 in. __6 2880 - top offset from the Form in Twips (1 in. = 1440 Twips). - 2 in. __7 2000 - width of Control in Twips (approx. 1,4 in). __8 300 - heigth of the Control in Twips (approx. .21 in). NOTE: To actually see this in action, place your Form in Design view, replace frmTest with your Form Name, create a Public Function Procedure, then run it from the Debug Window. Sorry that you asked this question?Comment
-
Originally posted by ADeziiWhat 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:
Code:Dim MyControl As Control Set MyControl = CreateControl("frmTest", acComboBox, acDetail, , "", 2880, 2880, 2000, 300) Parameter Explanations __1 frmTest - name of the Form on which you want to create the Control. __2 acComboBox - intrinsic Constant identifying Type of Control to create. __3 acDetail - intrinsic Constant identifying the Section that will contain the new Control. __4 "" - name of the Parent Control (if none, empty string). __5 2880 - left offset from the Form in Twips (1 in. = 1440 Twips). - 2 in. __6 2880 - top offset from the Form in Twips (1 in. = 1440 Twips). - 2 in. __7 2000 - width of Control in Twips (approx. 1,4 in). __8 300 - heigth of the Control in Twips (approx. .21 in). NOTE: To actually see this in action, place your Form in Design view, replace frmTest with your Form Name, create a Public Function Procedure, then run it from the Debug Window. Sorry that you asked this question?
Thank you for all your help!Comment
Comment