Sunday, 24 June 2012

DAO Programming Code Examples in VBA

This page is a reference for developers, demonstrating how to use the DAO library to programmatically create, delete, modify, and list the objects in Access - the tables, fields, indexes, and relations, queries, and databases - and read or set their properties.
There is no explanation beyond in-line comments, and no error handling in most examples.
Index of FunctionsDescription
CreateTableDAO()Create two tables using DAO, illustrating the field types.
ModifyTableDAO()Add and delete fields to existing tables.
DeleteTableDAO()Drop a table
MakeGuidTable()Create a table with a GUID field.
CreateIndexesDAO()Create primary key, foreign key, and unique indexes; single- and multi-field
DeleteIndexDAO()Delete indexes
CreateRelationDAO()Create relations between tables.
DeleteRelationDAO()Delete relations
DeleteQueryDAO()Delete a query programmatically.
SetPropertyDAO()Set a property for an object, creating if necessary.
HasProperty()Return true if the object has the property.
StandardProperties()Properties you always want set by default.
ConvertMixedCase()Convert mixed case name into a name with spaces.
SetFieldDescription()Assign a Description to a field.
IndexOnField()Indicate if there is a single-field index.
CreateQueryDAO()Create a query programmatically.
CreateDatabaseDAO()Create a new database programmatically, and set its key properties.
ShowDatabaseProps()List the properties of the current database.
ShowFields()How to read the fields of a table.
ShowFieldsRS()How to read the field names and types from a table or query.
FieldTypeName()Converts the numeric results of DAO fieldtype to text.
DAORecordsetExample()How to open a recordset and loop through the records.
ShowFormProperties()Loop through the controls on a form, showing names and properties.
ExecuteInTransaction()Execute the SQL statement on the current database in a transaction.
GetAutoNumDAO()Get the name of the AutoNumber field, using DAO.

1 comment:

  1. fantastic post and Thanks for sharing this info. It's very helpful.
    web agency brussels