180 likes | 228 Views
Learn to manipulate databases using DAO objects and methods in Visual Basic. Work with Recordsets and QueryDefs to access and modify data efficiently.
E N D
DBEngine Object • The DBEngine object contains and controls all other objects in the hierarchy of DAO objects.
Database object • You use the Database object and its methods and properties to manipulate an open database.
Recordset object-Methods A Recordset object represents the records in a base table or the records that result from running a query.
Function FindRecordCount(strSQL As String) As Long Dim dbsNorthwind As DAO.Database Dim rstRecords As DAO.Recordset On Error GoTo ErrorHandler Set dbsNorthwind = CurrentDb Set rstRecords = dbsNorthwind.OpenRecordset(strSQL) If rstRecords.EOF Then FindRecordCount = 0 Else rstRecords.MoveLast FindRecordCount = rstRecords.RecordCount End If rstRecords.Close dbsNorthwind.Close Set rstRecords = Nothing Set dbsNorthwind = Nothing Exit Function ErrorHandler: MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description End Function
Dim dbsNorthwind As DAO.Database Dim rstEmployees As DAO.Recordset Set dbsNorthwind = CurrentDb Set rstEmployees = dbsNorthwind.OpenRecordset("Employees") rstEmployees.MoveFirst Do Until rstEmployees.EOF If rstEmployees!Title = "Sales Representative" Then rstEmployees.Edit rstEmployees!Title = "Account Executive" rstEmployees.Update End If rstEmployees.MoveNext Loop
QueryDef object-Methods A QueryDef object is a stored definition of a query in a Microsoft Access database engine database.
TableDef object-Methods • A TableDef object represents the stored definition of a base table or a linked table (Microsoft Access workspaces only).