+ Reply to Thread
Results 1 to 3 of 3

Pass Variable In SQL Query In Excel VBA

  1. #1
    Registered User
    Join Date
    02-25-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question Pass Variable In SQL Query In Excel VBA

    Hi All,

    I am trying to pass a variable into a SQL Query, so that query is updated as per user input. But i am unable to execute it.
    below is the code:

    VBA:
    Please Login or Register  to view this content.
    I also tried using CHR(32) to insert a space but no success. Please help.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Pass Variable In SQL Query In Excel VBA

    Each separate "piece" of hardcoded text is surrounded by its own double quotes. So probably:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Pass Variable In SQL Query In Excel VBA

    I reckon you need
    Please Login or Register  to view this content.
    Name is usually a reserved word in SQL so you need to enclose it in []
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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