capture several items selected from combo box into an array for later save operation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • p4willi
    New Member
    • Jun 2010
    • 22

    #1

    capture several items selected from combo box into an array for later save operation

    VB6 Question

    Need to know how to capture several item selections from a single (as opposed to a multi selection) combo box drop down, into an array for later saving into a table on pressing the save button.
    I need a coded example please.
    Also, under which event (OnFocus, AfterUpdate.... ) would I put this.

    Thanks
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Using VBA? Try the OnClick event or if vb6.0, the click event...



    Good Luck

    Comment

    • p4willi
      New Member
      • Jun 2010
      • 22

      #3
      Thanks - but please show me with coded example how to store the captured items into an array.
      For example I choose the first item from the drop down and then click a check box, then come back to choosing another item from the same drop down and click another check box.
      All these chosen items and check boxes are to be stored temporarily - in an array - and finally when I press the save button it should write into a table.

      Comment

      • vb5prgrmr
        Recognized Expert Contributor
        • Oct 2009
        • 305

        #4
        A lot of sites and people frown upon those asking for code without trying for themselves to solve the problem...

        What is even more frowned upon by individuals is recieving a pm asking for code...

        So, I'll tell you what I will do. I'll give you some more hints on how to solve this...

        Use dynamic arrays for the strings and for the check boxes.
        Use ReDim Preserve to redimension your arrays to a larger size to hold the information.
        Use a variable or two to keep track of both of your arrays dimensions.
        The arrays and variables are to be declared in the general section of the form while the redim should be used in the event itself.



        Good Luck

        Comment

        • p4willi
          New Member
          • Jun 2010
          • 22

          #5
          Thanks for the tip. It worked.

          How do I reference this array, that I have built in a sub form from the save button on the main form?

          Comment

          • vb5prgrmr
            Recognized Expert Contributor
            • Oct 2009
            • 305

            #6
            Declare the array as public in the second form and when you/the user is done with the second form, don't unload it, hide it...

            in form1
            Code:
            Form2.Show vbModal, Me
            'rest of processing code here if needed
            in form2
            Code:
            Private Sub Command_Close()
            Me.Hide
            End Sub
            Then back in form1 when you click on save
            Code:
            Dim ForLoopCounter As Integer
            For ForLoopCounter = LBound(Form2.PublicArray) To UBound(Form2.PublicArray)
              '...
            Next ForLoopCounter


            Good Luck

            Comment

            • p4willi
              New Member
              • Jun 2010
              • 22

              #7
              Originally posted by vb5prgrmr
              Declare the array as public in the second form and when you/the user is done with the second form, don't unload it, hide it...

              in form1
              Code:
              Form2.Show vbModal, Me
              'rest of processing code here if needed
              in form2
              Code:
              Private Sub Command_Close()
              Me.Hide
              End Sub
              Then back in form1 when you click on save
              Code:
              Dim ForLoopCounter As Integer
              For ForLoopCounter = LBound(Form2.PublicArray) To UBound(Form2.PublicArray)
                '...
              Next ForLoopCounter


              Good Luck
              Thanks again - will give this a shot and let you know.

              Comment

              • p4willi
                New Member
                • Jun 2010
                • 22

                #8
                Originally posted by p4willi
                Thanks again - will give this a shot and let you know.
                Hi vb5prgrmr,
                What is the best way to capture several selections from a combo box of selections and for each selection two related checks (ticks).
                How would I store all these selections until I press the save button that inserts into the table.
                If there are there examples of such please point me to them.

                Thank you much

                Comment

                • vb5prgrmr
                  Recognized Expert Contributor
                  • Oct 2009
                  • 305

                  #9
                  Wow, I really thought I had answered this already...

                  Lets see, what have I written so far...

                  >Using VBA? Try the OnClick event or if vb6.0, the click event...

                  >Use dynamic arrays for the strings and for the check boxes.
                  >Use ReDim Preserve to redimension your arrays to a larger size to hold the information.
                  >Use a variable or two to keep track of both of your arrays dimensions.
                  >The arrays and variables are to be declared in the general section of the form while the redim should be used in the event itself.


                  Okay, yeah! I have given you all the hints you need to start building your code. So where is it? I mean, where is your code? What have you tried? Do you even know what an array is? Or a dynamic array? Do you know what a string is? And no, it is not something rolled up into a ball or on a spool that cats love to play with!

                  Please, try out some code. Look up dynamic arrays. Give it a go!


                  Good Luck

                  Comment

                  • p4willi
                    New Member
                    • Jun 2010
                    • 22

                    #10
                    Originally posted by vb5prgrmr
                    Wow, I really thought I had answered this already...

                    Lets see, what have I written so far...

                    >Using VBA? Try the OnClick event or if vb6.0, the click event...

                    >Use dynamic arrays for the strings and for the check boxes.
                    >Use ReDim Preserve to redimension your arrays to a larger size to hold the information.
                    >Use a variable or two to keep track of both of your arrays dimensions.
                    >The arrays and variables are to be declared in the general section of the form while the redim should be used in the event itself.


                    Okay, yeah! I have given you all the hints you need to start building your code. So where is it? I mean, where is your code? What have you tried? Do you even know what an array is? Or a dynamic array? Do you know what a string is? And no, it is not something rolled up into a ball or on a spool that cats love to play with!

                    Please, try out some code. Look up dynamic arrays. Give it a go!


                    Good Luck
                    Ok..Ok, i like the sarcasm..
                    I've got the arrays to work nicely. Every time the user selects from the combo and chooses check boxes, this set of selections is now stored into the array on the change event.

                    But how do I insert into the table only the last choice the user made (assuming he has made up his mind once and for all) thereby storing a unique choice?

                    Comment

                    • vb5prgrmr
                      Recognized Expert Contributor
                      • Oct 2009
                      • 305

                      #11
                      Use the UBound Function (if using dynamic arrays) to find out what the largest dimension is...



                      Good Luck

                      Comment

                      Working...