In addition to working with data and objects such as forms and reports in the Microsoft Access interface, you can use Microsoft Visual Basic to write procedures that dynamically create, delete, and modify data and objects. For example, you can write a procedure that places a caption on a form or that changes the color of a field on a form when a user performs a particular action.
You can refer to data and objects directly in your code, or you can declare object variables to represent them. After an object variable is declared and assigned, you can use it just as you would the name of the object it represents, and you can change its value, just as you can change the value of any variable.
For example, the following Sub procedure creates a table, Old Invoices, with a single field, OrderID:
Sub CreateTable ()
' Declare variables.
Dim dbs As Database, tbl As TableDef, fld As Field
' Assign the current database to the database
' variable.
Set dbs = CurrentDB
' Create a new table and field, and assign them
' to the table and field variables.
Set tbl = dbs.CreateTableDef("Old Invoices")
Set fld = tbl.CreateField("OrderID", dbText)
' Add the field to the table, then add the table
' to the database.
tbl.Fields.Append fld
dbs.TableDefs.Append tbl
dbs.TableDefs.Refresh
End Sub
Microsoft Data Access Objects (DAO) provides the objects, such as tables, queries, relationships, and indexes, that handle data-management tasks in a Microsoft Access database. These objects are called data access objects. You can share Visual Basic code that uses data access objects with other applications that use Microsoft DAO, such as Microsoft Excel.
You can also use Jet and Replication Objects to access and manipulate data in a database server through any OLE DB provider.
In addition, Microsoft Access defines a variety of objects that you use for working with data, such as forms, reports, and controls.
For more information on working with data access objects, click or see Building Applications with Forms and Reports. For more information about working with Jet and Replication Objects, click .