Consulting

Results 1 to 4 of 4

Thread: Creating a List Array for use in an ADO query

  1. #1

    Creating a List Array for use in an ADO query

    I am trying to run a query that returns the data only on certain dates. I've done it this way before with strings (ie to return string values from the datadase) but it doesn't seem to like the string with dates that I create. Am I missing something?

    My error message is:
    "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

    I don't think there is an Array List in VBA?

    [VBA]
    t = SDate & ", " & FDate & ", " & EDate

    cmd.CommandText = "SELECT hist_date, hist_price " & _
    "FROM history " & _
    "WHERE (name='TheName') AND (type='accounting') " & _
    AND (date ='" & t & "')"
    [/VBA]

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    What about something like [vba]cmd.CommandText = "SELECT hist_date, hist_price " & _
    "FROM history " & _
    "WHERE name='TheName' AND type='accounting' " & _
    "AND (date = " & SDate & " OR date = " & FDate & " OR date = " & EDate & ")"[/vba]
    Matt

  3. #3
    The problem though is that I might be querying from 100's of dates, which was why I was hoping to do something a bit more compact

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Surely, if there are hundreds of dates, it woulkd be more practical to write them to a database table, and then use that table in the query.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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