0

As the title states, I have a multiline textbox that I need to copy/paste multiple values into ( that'd exist on each line ) and have them turn into an array, which would build an SQL In statement. I'm already doing this with a listbox that works perfect, but can't figure out doing it with a textbox

My textbox is named form_payment_inv with multiline enabled.

Example of a copy/paste

1234
5678

Desired output would be

IN ('1234','5678')

1 Answer 1

1

You could do something like this:

Private Sub CommandButton1_Click()
    ' Split the text box's multiple lines by \r\n
    Dim myarr() As String
    myarr() = Split(TextBox1.Text, vbCrLf)

    ' Find total items contained in the array and put single quotes around them
    Dim TotalItems As Integer
    TotalItems = UBound(myarr)        
    Dim I As Integer
    For I = 0 To TotalItems
        myarr(I) = "'" & myarr(I) & "'"
    Next I

    ' create the IN statement
    Dim SQL_IN As String
    SQL_IN = Join(myarr, ",")
    MsgBox SQL_IN
End Sub

The result will be '1234','5678'

Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting "Expected Array" on TotalItems = UBound(myarr)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.