+ Reply to Thread
Results 1 to 9 of 9

SQL problems using ADO in vba

  1. #1
    Registered User
    Join Date
    08-26-2014
    Location
    gent
    MS-Off Ver
    2010
    Posts
    19

    SQL problems using ADO in vba

    I'm using ADO to read/write from an access database using excel vba.
    I used this sql without problems (strTable is a string with the name of my table in access)
    Please Login or Register  to view this content.
    But when I wanted to add a second criteria, it failed to open.

    Please Login or Register  to view this content.
    Anyone an idea how to solve this, what am I doing wrong?

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL problems using ADO in vba

    Perhaps this
    Please Login or Register  to view this content.
    otherwise I think you need to provide more detail as to what is happening. If you are simply not getting any records, it would seem the criteria are wrong.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    08-26-2014
    Location
    gent
    MS-Off Ver
    2010
    Posts
    19

    Re: SQL problems using ADO in vba

    Thanks for your reply.
    The problem is not that I don't get records, but that the code gives an error when executing the set command.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL problems using ADO in vba

    Did you test the version that I posted?

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: SQL problems using ADO in vba

    Print your final SQL string to the console, look for anything that looks wrong, and then try running that SQL string in the database itself. That will help narrow down if it is the specific SQL string or something else.

    Also expanding on xlnitwit's point, I find that it is best to enclose table and field names in square brackets regardless. Belt and braces, it's easy to do and can avoid potential headaches in the future.
    Design everything to be as simple as possible, but no simpler.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SQL problems using ADO in vba

    What's the error?
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-26-2014
    Location
    gent
    MS-Off Ver
    2010
    Posts
    19

    Re: SQL problems using ADO in vba

    The suggestion using [] did not help.
    I changed my code by first opening a recordset using only one criteria
    and then a filter command on the recordset to narrow to the only ones matching more than one criteria.
    This is working fine.
    Thanks for the suggestions

  8. #8
    Registered User
    Join Date
    08-26-2014
    Location
    gent
    MS-Off Ver
    2010
    Posts
    19

    Re: SQL problems using ADO in vba

    I don't know what the error was, the code was not executed.
    The error handler that I inserted before the command was called.
    Last edited by Bieke1111; 01-09-2018 at 11:42 AM.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SQL problems using ADO in vba

    There's no error handler in the code you posted.

    If you did have an error handler, what happens if you remove/comment it out?

    Do you then get an error message?

+ 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] Problems with sorting andf Pivot Table problems
    By Saturn in forum Excel General
    Replies: 4
    Last Post: 10-07-2012, 07:47 AM
  2. [SOLVED] If Problems.....
    By Macnautor in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-29-2012, 07:49 AM
  3. Replies: 0
    Last Post: 12-25-2011, 04:30 PM
  4. Excel 2007 : Problems with IF
    By 58teeth in forum Excel General
    Replies: 1
    Last Post: 12-13-2010, 03:44 PM
  5. Problems with DD/mm/YY
    By cruiser102 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2009, 04:08 PM
  6. Problems with the NAME box
    By bruinsmann in forum Excel General
    Replies: 1
    Last Post: 12-12-2007, 09:02 AM
  7. ''Sum problems''
    By NextByte in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 11-25-2007, 04:44 PM
  8. Problems with VB 6.0
    By filo666 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2005, 07:05 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