+ Reply to Thread
Results 1 to 4 of 4

SQL Query runs as pass-through but VBA returns error

  1. #1
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    SQL Query runs as pass-through but VBA returns error

    I would great appreciate if you can provide any guidance with this error. I have a VBA SQL query using a CASE WHEN statement that looks like this,

    HTML Code: 
    If I print the .commandtext string and paste this query in Access, it would return the answer that I need when run as pass-through. However since this is a loop reading multiple dates and locations, it must run using an ODBC connection using VBA. The error I receive is run-time error (missing operator) in query expression 'MORE THAN 15'.

    I tried converting if to IIF and SWITCH, but since I do not have a lot of experience with those functions, they would also return errors pointing to VOLUME_UNITS.

    Any help will be greatly appreciated. This is driving me insane.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: SQL Query runs as pass-through but VBA returns error

    can you paste the string thats created into here?
    If someone has helped you then please add to their Reputation

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

    Re: SQL Query runs as pass-through but VBA returns error

    Do you need the CASE statement in brackets?
    Martin

  4. #4
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: SQL Query runs as pass-through but VBA returns error

    @pjwhitfield

    There is the string generated by code

    HTML Code: 
    Again, this query would run in access as pass-through without any issues.

    @mrrice

    Yes, since I am naming the results as TotalItems

    Thanks for the help.

+ 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. Replies: 1
    Last Post: 09-08-2015, 08:12 PM
  2. Replies: 2
    Last Post: 10-06-2014, 08:15 AM
  3. Replies: 0
    Last Post: 10-06-2014, 07:35 AM
  4. [SOLVED] UDF returns #VALUE error, even though the function compiles and runs OK - help?
    By hadamhiram in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-26-2013, 01:29 PM
  5. Error handling web query that returns a non existent web page
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2013, 05:26 AM
  6. SQL Query with Excel VBA Returns General ODBC Error when Using Variables
    By Dirigo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2011, 03:05 AM
  7. [SOLVED] Web Query error returns
    By Peter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2006, 02:00 PM

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