Microsoft training courses | Wise Owl - home page

Phone (01457) 858877 or email

LINKING TO ADO DATABASES WITH VBA

Part one of a five-part series of blogs

Learn how to write VBA macros to add, edit and delete data in Access, SQL Server and other databases, using something called ADO.

  1. Linking to Data using VBA (this article)
  2. The ADO Object Library
  3. Of Connection Strings, Recordsets, Cursors and Locking
  4. Working with Records
  5. Finding Records Easily

This blog is part of both a complete Excel VBA tutorial and a complete SQL tutorial.

Posted by Andy Brown on 06 February 2012 | 1 comment

Linking to Data using VBA

Sometimes in Excel (for example) you'll need to retrieve data from a SQL Server table, an Access query or even a table in Oracle, Ingres or the like.  This blog explains how to do this!

This topic is stuffed full of theory about things like cursors and recordsets, but the strange thing is that the resulting code can be copied and pasted whenever you need to use it, without always needing to understand exactly what's going on behind the scenes! 

This tutorial shows how to connect to databases using VBA.  It covers:

  • Linking to the correct object library
  • Some theory on connection strings, recordsets, cursors and locking
  • Writing code to show, add, edit and delete records
  • Finding records

The first thing you'll need to do to work with database records is to link to the ActiveX Data Objects library (called ADO by its friends).

 

LINKING TO ADO DATABASES WITH VBA

Part one of a five-part series of blogs

Learn how to write VBA macros to add, edit and delete data in Access, SQL Server and other databases, using something called ADO.

  1. Linking to Data using VBA (this article)
  2. The ADO Object Library
  3. Of Connection Strings, Recordsets, Cursors and Locking
  4. Working with Records
  5. Finding Records Easily

This blog is part of both a complete Excel VBA tutorial and a complete SQL tutorial.

Comments on this blog

This blog has one comment:

Comment added by NewIdeas on 04 July 2012 at 23:42 GMT
I currently use ADO from one worksheet (say 2) to retrieve data from another worksheet (say 1), all within the same workbook (say workbook A) and it works fine.

In another workbook B, I have similar code but for some reason, it fails to retrieve data when workbook A is open.

Is there some sort of locking mechanism in place with SQL within Excel?


Reply from Andy Brown (blog author)
I have no idea, I'm afraid!  I'd suggest posting both samples of code at Stack Overflow with details of what goes wrong, and seeing if anyone there knows the answer.  If you find it, please let me know via another comment on this page - thanks.

All content copyright Wise Owl Business Solutions Ltd 2014. All rights reserved.