Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
538 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Posted by Andrew Gould on 02 April 2014
How to construct and manipulate command objects in ADO to talk to databases using VBA
See our full range of VBA training resources, or test your knowledge of VBA with one of our VBA skills assessment tests.
This video has the following accompanying files:
File name | Type | Description |
---|---|---|
GenerateUpdatedMoviesDatabase.sql | SQL query | |
Movies 2007.accdb | Access database (new format) | |
Top Movies 2012 ADO Commands.xlsm | Excel workbook with macros |
Click to download a zipped copy of the above files.
There are no exercises for this video.
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown above.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
To improve the quality of a video, first click on the Settings icon:
Make sure yoiu're playing your video so that the icons shown above appear, then click on this gear icon.
Choose to change the video quality:
Click as above to change your video quality.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option shown unless your connection speed is fast enough to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
From: | duggie |
When: | 09 Mar 20 at 12:26 |
This video shows how to use commandtext, whereas the previous video concentrates on recordsets.
Can you please explain the merits of using commandtexts over recordsets or is it just an alternative?
From: | Andrew G |
When: | 10 Mar 20 at 09:40 |
Hi, you can use Commands to execute SQL statements which don't return results to a Recordset, such as CREATE and DROP statements.
You can also use a Command to modify data without returning a Recordset which may give better performance, for example, using an UPDATE statement in a Command vs. retrieving a Recordset and altering its data.
I hope that helps!
From: | AceAxe |
When: | 02 Jun 19 at 11:49 |
Dear Andrew,
I'm having a problem with this lesson
I'm using SQL Server 2016 (installed by your instractions) and in this video you're using SQL Server 2012.
The problem is ConnectionString. Examples from "https://www.connectionstrings.com/sql-server-2016/" doesn't work at all
Using ConnectionString from Excel data Connection does do some work but useless to add anydata to database.
Here is my current ConnectionString "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=ma\new_sql2016;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MA;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=Movies"
Would you please excuse my ignorance and drop a small hint how to fix this problem.
Sincerely yours
Alexander
From: | Andrew G |
When: | 03 Jun 19 at 07:33 |
Hi there, here's some basic code which will work with the new version of the Movies database:
Const SQLConStr As String = _
"Provider=SQLNCLI11;Server=.\SQL2016;DataBase=Movies;Trusted_Connection=yes"
Sub ConnectToDB()
Dim MoviesConn As ADODB.Connection
Dim MoviesData As ADODB.Recordset
Dim r As Range
Set MoviesConn = New ADODB.Connection
Set MoviesData = New ADODB.Recordset
MoviesConn.ConnectionString = SQLConStr
MoviesConn.Open
On Error GoTo CloseConnection
With MoviesData
.ActiveConnection = MoviesConn
.Source = "Film"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
On Error GoTo CloseRecordset
Sheet1.Activate
For Each r In Range("A3", Range("A3").End(xlDown))
.AddNew
.Fields("Title").Value = r.Offset(0, 1).Value
.Fields("ReleaseDate").Value = r.Offset(0, 2).Value
.Fields("RunTimeMinutes").Value = r.Offset(0, 3).Value
.Update
Next r
End With
CloseRecordset:
MoviesData.CancelUpdate
MoviesData.Close
CloseConnection:
MoviesConn.Close
Set MoviesData = Nothing
Set MoviesConn = Nothing
End Sub
I hope that helps!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.