Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Copper Elite Contributor
Posts: 72
Registered: ‎04-01-2009

Add each checklistbox value into a text field

Hi all. We have SLX LAN v7.2.1.

 

I'm working with the checklistbox control (it has 4 values to choose from: A, B, C, D) and I'm trying to figure out a way to add the checklistbox values (that are checked by the end user) into a text field (mytext). The code below is what I have so far. I would like to add each value into mytext like this:

 

If there's just one value checked then = A

 

If there's 2 values checked then = A, B

 

If there's 3 values checked then = A, B, C

 

and if there's 4 values checked then = A, B, C, D

 

I would add the comma depending on how many values were checked in (if there was one then no comma). Any idea how I can do this? For now there will be 4 values, but in the future there could be 10, 20 , 30 so I would like to create script that will count how many are checked and from there know how many commas to add. Below is the script that I have so far, it inserts each value into a table (used for other purposes) but I'm missing the part where I want to fill in the text field (mytext) on the form.

 

Thank you in advance!

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'See how many checkboxes are filled in''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    j=0

    For i = 0 to CheckListBox1.Items.Count- 1

        If CheckListBox1.Checked(i) = True then

             j=j+1

         End If

    Next

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'This if-else checks to see if the end user filled in a product line checkbox.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    If j=0 then 'The end user did not fill in a checkbox

        Msgbox("You must select a product line")

    Else    'The end user filled in a checkbox, proceed to inserting into the C_PROMO_PRODUCTLINES table

        Set cn = Application.GetNewConnection

            For i = 0 to CheckListBox1.Items.Count- 1

           	 If CheckListBox1.Checked(i) = True then

                	sql_productlines="Insert into C_PROMO_PRODUCTLINES (C_PROMO_PRODUCTLINESID, C_PROMO_HEADER_ACCOUNTID, CREATEUSER,CREATEDATE, PRODUCTLINE) VALUES ('" &  Application.BasicFunctions.GetIDFor("C_PROMO_PRODUCTLINES") & "', '" & txtPromoHeaderID.Text  & "' ,'" & Application.BasicFunctions.CurrentUserID & "','" & NOW & "' ,'" & CheckListBox1.Items.Item(i) & "')"

	                cn.Execute sql_productlines

              End If  'Finish inserting into the C_PROMO_PRODUCTLINES table

            Next

 

    End If  ' End of the if-else that checks to see if the end user filled in a product line checkbox.

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

Copper Elite Contributor
Posts: 72
Registered: ‎04-01-2009

Re: Add each checklistbox value into a text field

I think I got it to work!

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This if-else checks to see if the end user filled in a product line checkbox.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If j=0 then 'The end user did not fill in a checkbox

        Msgbox("You must select a product line")

    Else    'The end user filled in a checkbox, proceed to inserting into the C_PROMO_PRODUCTLINES table

    txtProductLineString.Text = ""

        If j = 1 Then

            Set cn = Application.GetNewConnection

            For i = 0 to CheckListBox1.Items.Count- 1

                If CheckListBox1.Checked(i) = True then

                    sql_productlines="Insert into C_PROMO_PRODUCTLINES (C_PROMO_PRODUCTLINESID, C_PROMO_HEADER_ACCOUNTID, CREATEUSER,CREATEDATE, PRODUCTLINE) VALUES ('" &  Application.BasicFunctions.GetIDFor("C_PROMO_PRODUCTLINES") & "', '" & txtPromoHeaderID.Text  & "' ,'" & Application.BasicFunctions.CurrentUserID & "','" & NOW & "' ,'" & CheckListBox1.Items.Item(i) & "')"

                    cn.Execute sql_productlines

                    txtProductLineString.Text = CheckListBox1.Items.Item(i)

                End If  'Finish inserting into the C_PROMO_PRODUCTLINES table

            Next

        Else

            Set cn = Application.GetNewConnection

            For i = 0 to CheckListBox1.Items.Count- 1

                If CheckListBox1.Checked(i) = True then

                    sql_productlines="Insert into C_PROMO_PRODUCTLINES (C_PROMO_PRODUCTLINESID, C_PROMO_HEADER_ACCOUNTID, CREATEUSER,CREATEDATE, PRODUCTLINE) VALUES ('" &  Application.BasicFunctions.GetIDFor("C_PROMO_PRODUCTLINES") & "', '" & txtPromoHeaderID.Text  & "' ,'" & Application.BasicFunctions.CurrentUserID & "','" & NOW & "' ,'" & CheckListBox1.Items.Item(i) & "')"

                    cn.Execute sql_productlines

                        If txtProductLineString.Text = "" Then

                            txtProductLineString.Text =CheckListBox1.Items.Item(i)

                        Else

                            txtProductLineString.Text = txtProductLineString.Text & " AND " & CheckListBox1.Items.Item(i)

                        End If

                End If  'Finish inserting into the C_PROMO_PRODUCTLINES table

            Next


        end if

    End If  ' End of the if-else that checks to see if the end user filled in a product line checkbox.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''