Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Split function problem (MS ACCESS 2003)

    i am getting a subscript out of range on sTArr(1)

    I think its because the word its trying to split has no space.
    How do I overcome the problem, thanks


    Dim sT As String, sTArr, j

    sT = Me.Words.Caption
    sTArr = Split(sT, " ")

    If IsNull(sTArr(1)) = False And IsNull(sTArr(0)) = False Then
    Me.List53.AddItem sTArr(1) & " " & sTArr(0)
    End If

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Split function problem (MS ACCESS 2003)

    You can inspect UBound(sTArr) first. If this is 0, there is no sTArr(1).

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Split function problem (MS ACCESS 2003)

    Thanks Hans. I tried this, but it still reports subscript out of range on sTArr(1) ?? Thanks

    sTArr = Split(sT, " ")



    For j = LBound(sTArr) To UBound(sTArr)

    If sTArr(0) > 0 And sTArr(1) > 0 Then
    Me.List53.AddItem sTArr(1) & " " & sTArr(0)
    Else
    DoCmd.Beep
    End If

    Next

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Split function problem (MS ACCESS 2003)

    Of course, if UBound(sTArr) = 0 you can't refer to sTArr(1).

    If UBound(sTArr) > 0 Then
    If sTArr(0) > 0 And sTArr(1) > 0 Then
    Me.List53.AddItem sTArr(1) & " " & sTArr(0)
    End If
    End If

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Split function problem (MS ACCESS 2003)

    Thanks Hans, very greatful for help. Works fine now. Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •