Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Mar 2007
    Location
    Wikltshire UK
    Posts
    152
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Split and Array as Variant (MS Access/VBA 2007)

    This is driving me potty. I have one Variable i'm declaring as a Variant and then assigning values via SPLIT which works fine (First Example) and then I'mm trying to do it again and the second just gives me a TYpe Mismatch Why they are both assigned to Text Columns. The only difference I can see is that one gets assigned intially to splittable data in the sequance and the other dosn't??

    As I say PartsT works fine BusDaysTemp does not.


    Dim BusDayStore As Variant
    Dim PartsT As Variant

    If IsNull(RST.Fields("Payment Days").Value) Then
    PayDays = ""
    Else
    PayDays = RST.Fields("Payment Days").Value
    End If

    If IsNull(RST.Fields("Business Day").Value) Then
    BusDay = ""
    Else
    BusDay = RST.Fields("Business Day").Value
    End If

    If InStr(BusDay, ",") Then
    BusDayStore = Split(BusDay, ", ", 99)
    Else
    BusDayStore(0) = BusDay
    End If


    If InStr(PayDays, ",") Then
    PartsT = Split(PayDays, ",", 99)
    Else
    PartsT(0) = PayDays
    End If

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

    Re: Split and Array as Variant (MS Access/VBA 2007)

    If a variable V of type Variant hasn't been assigned an array before, V(0) doesn't make sense, for at that point V is not an array. Once you have assigned an array to V, you can refer to V(0) without problems.
    You could use the following instead of BusDayStore(0) = BusDay:

    BusDayStore = Array(BusDay)

    This will have the same effect and it will work even if BusDayStore hasn't been assigned an array before.

  3. #3
    2 Star Lounger
    Join Date
    Mar 2007
    Location
    Wikltshire UK
    Posts
    152
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Split and Array as Variant (MS Access/VBA 2007)

    Yep Fantastic. "You da Man" Hans

Posting Permissions

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