Consulting

Results 1 to 4 of 4

Thread: loading array with dates

  1. #1

    loading array with dates

    I'm trying to load an array with a series of dates. I keep getting a 'subscript out of range' error, which I assume means that the date is coming in the wrong format, maybe?
    The data being read (we!WEdate) is a date format field.

    Here is my code:
    Option Base 1
    'define the array
    Dim A() As Variant, i As Integer
    A = Array(52)
    ____________________________________________
    'after defining the database and recordset:
    
    we.MoveFirst
    i = 1
    rewe:
    If we.EOF Then GoTo Donewe
    A(i) = we!WEDate
       i = i + 1
    we.MoveNext
    GoTo rewe
    Donewe:
    we.Close
    _____________________________________________________
    I've also tried this:
    A(I) = "#" & we!WEDate & "#"
    _____________________________________________________

    what am I doing wrong? It's been years since I've worked with arrays, because I do very little development work now.
    Last edited by Bob Phillips; 04-09-2019 at 02:48 AM. Reason: Added code tags

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    It could be that you need to redim the array before filling it.
    This works for me

    Dim A As Variant, i As Integer
    ReDim A(0 To 5) As Variant
    A(0) = Date
    A(1) = Date + 1
    MsgBox A(0) & " " & A(1)

  3. #3
    OBP:
    Yes, that works. Thanks a lot.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location

Posting Permissions

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