Share this Page URL

Chapter 17. Using Visual Basic to Manage... > Working with Recordsets in ADO - Pg. 606

Using Visual Basic to Manage Data 606 A. You need to include a reference to the object library in the Visual Basic project, and you need to declare object variables using specific data types rather than the generic Object type. Working with Recordsets in ADO In Chapter 5 we introduced ADO, a data access object model that you can use to manage data in an Access database. We described the ADO Connection object and the ADO Recordset object, providing an example of how to use methods of the ADO Recordset object to add a record to the MarketingCampaigns table in the HelloWorld database. Here's the code we used in that demon- stration: Private Sub cmdAddRecord_Click() Dim adoRst As ADODB.Recordset Set adoRst = New ADODB.Recordset adoRst.ActiveConnection = CurrentProject.Connection adoRst.Open "MarketingCampaigns", , adOpenDynamic, adLockOptimistic adoRst.AddNew adoRst("Country") = txtCountry.Value adoRst("LaunchDate") = txtLaunchDate.Value adoRst.Update DoCmd.OpenTable "MarketingCampaigns", acViewNormal, acReadOnly adoRst.Close Set adoRst = Nothing In this section, we'll build on this example to describe some of the other actions you can carry out after using ADO to connect to a database and open a recordset.