+ Reply to Thread
Results 1 to 2 of 2

Getting results of a SQL query on an Access database into a worksheet

  1. #1
    Registered User
    Join Date
    02-27-2019
    Location
    US
    MS-Off Ver
    2016 Excel
    Posts
    4

    Unhappy Getting results of a SQL query on an Access database into a worksheet

    I am trying to write a VBA macro that will output the results of a SQL query run off an Access database.

    The SQL script uses 4 different tables in the Access database, and the SQL script isn't saved as a query in the Access database.

    How can I write a macro that links to the Access database, runs the SQL script I provide, and spits out the results into an Excel worksheet?

    I really am not sure where to start with this. I've found this example code
    Public Sub DoSQL()

    Dim SQL As String

    SQL = "UPDATE Employees " & _
    "SET Employees.Title = 'Regional Sales Manager' " & _
    "WHERE Employees.Title = 'Sales Manager'"

    DoCmd.RunSQL SQL

    End Sub
    But I'm not sure how VBA knows where the "Title" table is? Any help is appreciated!!

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Getting results of a SQL query on an Access database into a worksheet

    I guess you mean run from Excel?

    There are many examples, search for ADO.

+ 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. Is it Possible to Open an Access Database Query and copy results
    By gassiusmax in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-09-2015, 07:24 AM
  3. Query Access Database
    By BN-CD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2006, 11:12 PM
  4. Replies: 2
    Last Post: 03-08-2006, 04:45 PM
  5. Database Query-a query that reads data from MS Access
    By Osmar Mateus in forum Excel General
    Replies: 4
    Last Post: 01-29-2006, 04:10 PM
  6. [SOLVED] Help with Access Database Query!!
    By Vince in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-16-2005, 01:06 PM
  7. MS Access record delete from excel database query results
    By sdnicsm in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-23-2005, 03:55 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