Trying to specify a range with sql string and vba variables

Posted on 2010-01-06
Last Modified: 2012-05-08
instead of just
"Select * From invoices Where [Invoice Date] >= #" & myval & "#"
I would like:
"Select * From invoices Where [Invoice Date] >= #" & myval & "#" & <= myval2 and ... , is there some command program that could give me the correct syntax for any sql string - if not could anyone give me the correct syntax for the above.
Question by:Jimmy_inc
    LVL 39

    Accepted Solution

    I believe it would be something like this:

    "Select * From invoices Where [Invoice Date] >= #" & myval & "# AND [Invoice Date] <= #" & myval2 & "#"

    Just build the sql string, then replace the parts with variables making sure your & and your " are matching.

    LVL 22

    Assisted Solution

    by:Kelvin Sparks
    You can also use
    "Select * From invoices Where [Invoice Date] BETWEEN #" & myval & "# AND #" & myval2 & "#"


    Author Closing Comment

    Thanks worked perfectly.

     Im going to post another question for you guys

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now