Learn how to write VBA macros to add, edit and delete data in Access, SQL Server and other databases, using something called ADO.
- Linking to Data using VBA (this blog)
- The ADO Object Library
- Of Connection Strings, Recordsets, Cursors and Locking
- Working with Records
- Finding Records Easily
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).
This blog has 1 comment
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?
A full-blown discussion forum is being built for this site, which will allow you once more to add comments and discussion threads.