Adding items to combo box during run time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mysore
    New Member
    • Jul 2007
    • 8

    #1

    Adding items to combo box during run time

    I am using VB6.0

    I have two combo boxes , namely combo1 and combo2.
    For E.g, I say Combo1.AddItem Combo1.Text to add a new item to the list during run time. In the drop down I do see the new item during run time. But It disappears in the next run time.

    My question is , how can I save the newly added item to the Combo boxes list permanently so that in the next run time it should show the new added item along with the old items.

    Please help.

    Thanks
    Pratibha
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by mysore
    I am using VB6.0

    I have two combo boxes , namely combo1 and combo2.
    For E.g, I say Combo1.AddItem Combo1.Text to add a new item to the list during run time. In the drop down I do see the new item during run time. But It disappears in the next run time.

    My question is , how can I save the newly added item to the Combo boxes list permanently so that in the next run time it should show the new added item along with the old items.

    Please help.

    Thanks
    Pratibha
    So you have to store it in database.

    Comment

    • mysore
      New Member
      • Jul 2007
      • 8

      #3
      Originally posted by hariharanmca
      So you have to store it in database.
      Yeah. I am using MS access.

      Comment

      • pureenhanoi
        New Member
        • Mar 2007
        • 175

        #4
        Originally posted by mysore
        Yeah. I am using MS access.
        after adding new item into ComboBox, insert it into database.
        If u bind combobox into a table, it will be automatically added new item into table. If u was not, add new item by manual.
        ComboBox1.AddIt em Combo1.Text
        Code:
        sql = "INSERT INTO tableName '" & combo1.Text & "'"
        Conn.Excute sql
        later, u load all from and all item into combobox, new item will appear

        Comment

        • ENTBedford
          New Member
          • Jun 2007
          • 7

          #5
          Just a reminder....

          If combobox items never have to change they can be set when the form and control are designed and will always revert to the original design contents when the application is restarted.

          If the combobox items have to be set or changed at runtime and then have to be saved for next time, the items will have to be saved outside the application. This can be either in a database or in a separate data/text file (written with streamreader and writer). The combobox will have to be filled from and saved to the database or file each time the application is run.

          This is one of those things that if you know you know, but if you don't you spend hours wondering why what you want to do doesn't work. And that's what the forums should help with.

          Comment

          • fplesco
            New Member
            • Jul 2007
            • 82

            #6
            Originally posted by mysore
            I am using VB6.0

            I have two combo boxes , namely combo1 and combo2.
            For E.g, I say Combo1.AddItem Combo1.Text to add a new item to the list during run time. In the drop down I do see the new item during run time. But It disappears in the next run time.

            My question is , how can I save the newly added item to the Combo boxes list permanently so that in the next run time it should show the new added item along with the old items.

            Please help.

            Thanks
            Pratibha
            Hi there -

            I can figure out your problem. Those values in the combo box that you said that are not gone after rerun, are really values it at your design time. Try to look at Combo box "List" property at the design time and you will those values.

            Now, you may have wanted it all coming from your database (MS Access). What you gonna do is

            I suppose that you know how and you are able to connect to the dbase and your recordset object is ready.

            Combo1.clear -- This will clear the values from design time
            If not rs.eof -- And load values extracted from your table in the dbase
            Do until rs.eof
            Combo1.AddItem rs!<Fieldname>
            Loop
            End if

            This perhaps shed light to this problem.

            Have a good day.

            Comment

            • mysore
              New Member
              • Jul 2007
              • 8

              #7
              Thanks everyone. It worked. Your replies solved my problem.

              Thank You.

              Pratibha

              Comment

              Working...