COMBO BOX...create with code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ineedahelp
    New Member
    • Sep 2006
    • 98

    COMBO BOX...create with code

    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!
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    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:

    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
    This will activate the second combo when a selection has been made.
    Getting the idea ?

    Nic;o)

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by ineedahelp
      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:

      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

      • ineedahelp
        New Member
        • Sep 2006
        • 98

        #4
        Originally posted by ADezii
        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:

        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

        Working...