Consulting

Results 1 to 5 of 5

Thread: Solved: SQL Problem

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: SQL Problem

    I have a userform in excel which links to an access database and runs an sql query giving the results in a userform

    I use the code below for the query

    strSql = "SELECT * From Applications WHERE Applicant= '" & txtSearch & "';"

    What I need to be able to do is run an SQL query that checks if column due_Date is before today and Column Submitted_Date is not a null value (i.e. blank)

    I know this is not strictly an excel question but my interface is excel based and you ve helped me with similar in the past

    cheers

    Gibbo

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can't terst, but I think this will work

    [VBA]
    strSql = "SELECT * From Applications " & _
    "WHERE Applicant= '" & txtSearch & "' AND " & _
    " due_Date < #" & Format(Date, "dd/mm/yyyy") & "# AND " & _
    " submitted_Date <> ''"
    [/VBA]
    ____________________________________________
    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

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Gibbo

    The best way to get this SQL would be to query in Access.

    Then copy it Excel VBA, altering it as needed.

  4. #4
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Gibbo,

    As Bob shows the date expressions must be placed between # and where we use the logical expressions (>,<,<>,= etc). Pay also attention to the apostrophe in use.

    Given that the approach is adapted Norie points out a good way to play around with SQL-expressions.

    Kind regards,
    Dennis
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  5. #5
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks all,

    Tried Norie's approach and edited it as per my needs

    Gibbo

Posting Permissions

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