+ Reply to Thread
Results 1 to 5 of 5

Coding for a date parameter.

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Coding for a date parameter.

    I am trying to code the building of an sql string to download some data from SQL server into excel.
    Please Login or Register  to view this content.
    I get an error message on the WHERE clause of the SQL string marked with XX XX. I hope I have my ' and " in the right places but I am not sure. Can any one help me with the correct syntax?

    I had some very useful help on coding a single date a few weeks back and I am disappointed that I have been unable to extend this to a two date situation.
    John

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Coding for a date parameter.

    When you debug.print strsql. What's the exact string that's shown?

    I think you are missing single space before "AND" but not sure.

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Coding for a date parameter.

    It also appears that there should be a space before the first apostrophe, and I would suggest using yyyy/mm/dd format
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Coding for a date parameter.

    The value of sqlstr when optionbutton 1 was clicked was (from Debug.Print)
    SELECT hafgfk__.fak__ref, hafgfk__.dok__dat FROM sqlb00.dbo.hafgfk__ hafgfk__WHERE (hafgfk__.dok__dat Between' 03/21/2017 'AND ' 03/21/2017 ')

    I think I have managed to get the coding around the parameter dates right. However there is still an error message telling me that the hafgfk__ in the WHERE clause is not a recognised "table hints option"
    If I REM out the WHERE clause, the SELECT and FROM clauses work fine. So hafgfk__.dok__dat was accepted in that case. I am confused and a little out of my depth.
    John

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Coding for a date parameter.

    You are missing space before "WHERE" and and you got extra spaces inside single quotes...

    Try below, with added space to xlnitwit's modification. Change date format as needed (I usually use yyyy-mm-dd myself).

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Coding a Query parameter
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2017, 02:58 PM
  2. Coding a parameter in a SQL string for a query
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-05-2017, 05:24 AM
  3. Replies: 2
    Last Post: 10-06-2014, 08:15 AM
  4. Replies: 0
    Last Post: 10-06-2014, 07:35 AM
  5. [SOLVED] MSquery date parameter
    By Goldbadger2 in forum Excel General
    Replies: 1
    Last Post: 03-13-2014, 11:31 AM
  6. Parameter Query that takes parameter value from Excel Cell
    By Aquamore in forum Access Tables & Databases
    Replies: 1
    Last Post: 01-23-2014, 03:43 PM
  7. Replies: 0
    Last Post: 11-12-2013, 03:57 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1