+ Reply to Thread
Results 1 to 2 of 2

Excel VBA Querying SQL Server including Sheet Cell Reference in Query

  1. #1
    Registered User
    Join Date
    11-11-2015
    Location
    FL
    MS-Off Ver
    MS Office 2016
    Posts
    5

    Question Excel VBA Querying SQL Server including Sheet Cell Reference in Query

    Good Afternoon, Everyone! I'm trying to put together a workbook that queries a SQL server and have been successful in using the original vb code, but when I try to include a 'WHERE' in the SQL statement, it doesn't work. Here is what I have that works and returns all records. I have tried multiple ways of putting a 'WHERE' clause after 'FROM table' with all of them failing. What I'm trying to accomplish is, in Sheet1 of my workbook, I have Cell B4 that I would like the SQL statement to reference; (i.e. return records 'WHERE name = B4). I greatly appreciate anyone and everyone's help!

    This code, immediately below, works to return all records from the table.
    Please Login or Register  to view this content.
    I've tried, to no avail:

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

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Excel VBA Querying SQL Server including Sheet Cell Reference in Query

    I think you are missing the quotes around the B4 value, e.g.

    Please Login or Register  to view this content.
    I assume B4 value is some string/text
    If you are pleased with a member's answer then use the Star icon to rate it.

+ 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] Using cell reference as a value in a Excel VBA SQL Query
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-11-2013, 01:10 PM
  2. Replies: 2
    Last Post: 02-01-2013, 04:21 PM
  3. Excel Query With link To SQL Server
    By yorkshirewhite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2011, 01:44 AM
  4. Querying a remote PH server?
    By daemonsan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-13-2007, 03:53 PM
  5. Excel Query connection to Server Help...
    By ImtiazV in forum Excel General
    Replies: 0
    Last Post: 08-03-2007, 11:04 AM
  6. Excel not finding the server in web query
    By JM in forum Excel General
    Replies: 0
    Last Post: 02-12-2006, 06:50 PM
  7. [SOLVED] Querying a SQL Server Database
    By Chaplain Doug in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-14-2005, 01:45 PM
  8. Querying an excel sheet
    By Jay in forum Excel General
    Replies: 0
    Last Post: 01-12-2005, 05:06 AM

Tags for this Thread

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