+ Reply to Thread
Results 1 to 9 of 9

SQL from access not working in VBA

  1. #1
    Registered User
    Join Date
    07-06-2015
    Location
    Manchester, UK
    MS-Off Ver
    2010
    Posts
    7

    SQL from access not working in VBA

    Hi all, I have used the query designer in access to create the following code.

    Please Login or Register  to view this content.
    I am trying to use this in excel to run a query from there.

    The only thing I have changed is the criteria, streamstr, division str and Date1 are all vba variables, I can't get this code to work, I have changed it a few times now and still can't get it functional,

    Any help would be appreciated,

    Thanks

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,176

    Re: SQL from access not working in VBA

    I think it may be your double-double quotes.
    Try using a single quote. Access will accept single quotes around strings.

    or dont use VB, save this as a query , and the quotes wont matter.

  3. #3
    Registered User
    Join Date
    07-06-2015
    Location
    Manchester, UK
    MS-Off Ver
    2010
    Posts
    7

    Re: SQL from access not working in VBA

    I've updated the code a bit

    Please Login or Register  to view this content.
    I get an Expected end of statement on the first INNER of line 2, and an Expected expression error on the first single quotation on line 3

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: SQL from access not working in VBA

    Access gets the monk on if you don't include parentheses around your joins

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: SQL from access not working in VBA

    Hi, I see a number of problems here, first of all your string is all broken up... you need to close each line with a " and then & _ in order to be able to build a string on multiple lines, so it would look like:

    Please Login or Register  to view this content.
    but additionally you seem to be trying to do an inner join between two inner joins? The syntax seems off to me, but since I don't have the database I can't really play around with it. I might suggest building 2 queries in access to perform the two sides of the inner joins, then you can use excel to run the inner join between those two.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: SQL from access not working in VBA

    I think you want:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-06-2015
    Location
    Manchester, UK
    MS-Off Ver
    2010
    Posts
    7

    Re: SQL from access not working in VBA

    Thanks, I have tried using that code and it returns a syntax error : missing operator

    Here is the code as it stands at the moment.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: SQL from access not working in VBA

    You need a space at the end of each row

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: SQL from access not working in VBA

    Or the start of the second and third... but yes there needs to be a bit of space to separate where one line ends and the next starts. Best practice is always end the line with a space, then quote

+ 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. Double Handling within working code Write to access and fire access macro
    By robtuby in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-11-2015, 12:19 PM
  2. [SOLVED] Access Query with <> is not working properly
    By VKS in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-24-2013, 03:31 AM
  3. Merge Cells Not Working through Access
    By racer25 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2013, 04:48 PM
  4. SQL From Access Not Working
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2006, 05:10 PM
  5. Replies: 6
    Last Post: 02-10-2005, 05:06 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