+ Reply to Thread
Results 1 to 10 of 10

Coding of parameter date queries

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

    Coding of parameter date queries

    I am having problems trying to write an SQL command which contains parameters to allow the selection of a date range over which to query a database.
    In order to simplify things I am first just querying for data where the dates are >= to a given date using the code below.
    Please Login or Register  to view this content.
    This however gives me a "Type Mismatch" error on the line marked ********
    I can't see why. Can anyone else?
    John

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Coding of parameter date queries

    The the highlighted line, you have a * instead of a &. Excel is objecting because you are trying to multiply to text strings .
    Martin

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

    Re: Coding of parameter date queries

    mrice,
    Thank you for your interest in my problem. I first punched the air in delight as I read your post as it presented such an easy solution to a problem that has plagued me on and off for weeks. Sadly however I think that the * must be a smudge on you screen. On my computer both &'s are in place.
    To be quite certain I deleted both and retyped them. I got the same error.
    John

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Coding of parameter date queries

    I copied the code directly from your post and, while my screen is far from clean, there is an asterisk in this line - see the attachment.

    When I replace it with an ampersand the final SQL statement looks like below.


    Please Login or Register  to view this content.
    Attached Images Attached Images

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Coding of parameter date queries

    John

    Where/when do you get the 'type mismatch' error?

    I can run the posted code, with the typo fixed, without problem.

    What type of database, eg Access, MSSQL, MySQL etc, are you querying anywhere?
    If posting code please use code tags, see here.

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

    Re: Coding of parameter date queries

    First mrice, I have to apologise for impugning the cleanliness of your screen. I have now seen the wayward * and changed it to the & required. Many thanks for your help.
    Second to mrice and norie. With the typo removed the sub ran through without error. However when the 'DownLoad' was run it ended with the error "SQL syntax error on the last line. the full code is:-
    Please Login or Register  to view this content.
    I have excluded lines 10,20,30 in turn and find that it is lines 10 and 30 that cause the error.
    It is my intention when this is sorted, to code two parameters FromDate and ToDate
    It seems I still have not got the hang of how to deal with dates or parameters, and I still need help
    John

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

    Re: Coding of parameter date queries

    I have managed to get the syntax right by removing the "d" qualifier and its associated brackets. The following code works when the "AND" lines are run separately.
    When run as shown here though the last line is ignored and all Transaction Types and VAT codes are listed.
    I think this must mean that my brackets are wrong.
    Please Login or Register  to view this content.
    I am not certain of the rules to cover this bracketing so I could do with some help please
    John

  8. #8
    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 of parameter date queries

    Hi,

    You have two more closing brackets than opening brackets, so that query shouldn't work at all.

    Returning to your original syntax, I believe the brackets around the dates should be curly brackets so
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Coding of parameter date queries

    John

    You shouldn't need any brackets and having brackets shouldn't make a difference either so I don't think that's where the problem lies.

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

    Re: Coding of parameter date queries

    My only reference on the subject is a book called Teach yourself SQL in 10 minutes published in 2001! I wouldn't put a huge amount of faith in it but it does say that AND clauses ought to be put in brackets (not, I admit, Must be) and generally advises their use to ensure that their order of evaluation is what you want. On further examination I realise that the brackets I had did not do this, so I redid them to this
    Please Login or Register  to view this content.
    Which is pretty much as xlnitwit has given above and glory of glories it all works!!!
    I must just let you know xlnitwit, Norie and mrice how very grateful I am at all your help. I have had to come back to one aspect or another of the problem 0f getting data out of Sage Line 100 week after week, it is such a relief to be able with your help, to put it to bed.
    John

+ 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 for a date parameter.
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-21-2017, 11:28 AM
  2. [SOLVED] Coding a Query parameter
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2017, 02:58 PM
  3. 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
  4. Parameter Queries
    By j_Southern in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-04-2013, 09:59 AM
  5. [SOLVED] Tournament simulation and coding queries
    By alaska_1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2012, 03:23 PM
  6. Parameter queries
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-07-2010, 07:08 AM
  7. [SOLVED] Where can I learn how to create parameter queries in Excel?
    By Mark in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 10:31 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