MS Access 2003 VBA String Split on Line Break

2019-04-09 14:07发布

问题:

I have a textbox on a MS Access form that users are going to copy a column of numbers into from an excel spreadsheet. I need to take this input and use it as parameters to build a query. I have code that looks like this

Dim data as variant
Dim input as String
data = Split(input,vbLf)

I want to be able to build a list of the input from the users but I can't figure out how to split it on the line break. I've tried "\n\r", "\n". "\r", vbCrLf, vbLf. The input looks like "12345[][]23456" with the box characters between each number

Thanks

回答1:

I got Split to work for me using vbCrLf. I also wrote the result of Split to a String array.

Here's my code:

Dim data() As String
Dim yourInput As String
data = Split(yourInput, vbCrLf)


回答2:

vbCRLF worked for me, try: Strings.Chr(13) & Strings.Chr(10) (which is vbCRLF)

try to see what is the ASCII code of those 2 boxes:

    //ex for input = "12345[][]23456"
    Strings.Asc(Strings.Mid(input, 6, 1)) 
    Strings.Asc(Strings.Mid(input, 7, 1))