Results 1 to 16 of 16

Thread: How to add element in ComboBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Exclamation How to add element in ComboBox

    hi all,

    i want to add one elsement at o'th index of ComboBox ...
    like this
    "---Select---"
    how can i do thisd and on which event ??
    pls help me regarding this with code..

    thanx in advance
    Nilesh Thakur.

  2. #2
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: How to add element in ComboBox

    You can use
    Code:
    Sub ComboBox1_Change()
    Me.ComboBox1.Value = "----Select----"
    End Sub
    or in the properties add "Select" to the value property

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to add element in ComboBox

    Are you using word?access?excel?


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    ohh i am sorry,
    i am using access and i want to add new element on 0'th index as
    "--select--" and user should able to see this "--select--" before user select any thing from ComboBox
    Nilesh Thakur.

  5. #5
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: How to add element in ComboBox

    Hello,

    You could also set the text property of the combobox.

    Once a user selects something else the Select will be gone.

    J

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    thanx Killazzz ,
    i have try as per you say but it wount work...

    thanx
    Nilesh Thakur.

  7. #7
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: How to add element in ComboBox

    Nile,

    You go to your table. Click on the Design feature. Go to "combobox1" under the field properties section click on default value and input your value there.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    Hi jmhfloor,

    i had try the solustion which you told me, i have done this step's but no result Dude..(Click on the Design feature. Go to "combobox1" under the field properties section click on default value and input your value there)
    pls help me any one...

    thanx in advance,

    Regards
    Nilesh Thakur.

  9. #9
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: How to add element in ComboBox

    to add element to a combobox, use the code combo1.additem "your element here"
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to add element in ComboBox

    Is your combo box bound to a table or something?

    Just using combo1.additem "your element here" will add it to the end of the dropdown list.
    You need to specify the index position of 0 to get it as the first item.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    hi all,

    yes i have one Combo Box which is retrive value from one table and i have one sub form on same form when i select records from Combo box subform will show me records according to that selecttion, when i search the property Combobox1.additem it is not there .... i am doing all this in Access as i told early thanx and pls help me regarding this ...

    i am not able to find the property like combo1.additem "your element here"

    thanx in advance,
    Nilesh Thakur.

  12. #12
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to add element in ComboBox

    Hi!!!

    Click on the properties of the combo box....Locate the record source type (this should be table/query) for record source choose the table in the drop down list...

    I suppose your going to use ADO/DAO code for that since your project specification requires you to select a value in the combo box and change the data in your subform...Have you tried using DAO/ADO?



  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    hay KGC,

    thanx for your help,

    i am new in Access i did't know about the ADO/DAO i only select DropDown From ToolsBox and place it on form it ask me to ( I want ComboBox to LookUp the Values in a table or Query ) and i link it .. that's it..

    thanx,
    Nilesh Thakur.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: How to add element in ComboBox

    Hi all,

    pls help me......

    thanx in advance,
    Nilesh Thakur.

  15. #15
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: How to add element in ComboBox

    which version of Access are you using and the term "combobox1" is a generic term I was using in place of the name of the combobox you are trying to name.

    When you go to your table and go into design view. Select the name of the combobox and there will be a set of fields at the bottom of that screen find the section for Default Value. This sets the combo box to this name every time it opens. When you select a different value from your list it will change the name on the default value to your value you selected and store that information in the table for the new record.

    I have attatched a generic table form to show you what I mean when this happens.

    (I have access 2000 and using this exact technique.)
    Attached Files Attached Files
    Last edited by jmhfloor; Mar 3rd, 2006 at 09:28 AM.

  16. #16
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to add element in ComboBox

    Hi...

    I suppose you have a table named customer with a primary key of CustomerID..And in your form you added textboxes bound to the fields and the combo box for searching the customerID.The combo box is not bound to the table.The record source type should be Table/Query...Use sql statement in the record source of the combo box....

    Example...

    Select Customer.CustomerID, Customer.CustomerName, Customer.CustomerAddress from Customer;
    Then in your combo box named Combo8, attach this code...


    VB Code:
    1. Private Sub Combo8_AfterUpdate()
    2.     ' Find the record that matches the control.
    3.     Dim rs As Object
    4.  
    5.     Set rs = Me.Recordset.Clone
    6.     rs.FindFirst "[CustomerID] = " & Str(Nz(Me![Combo8], 0))
    7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    8. End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width