This page contains information related to products such as Microsoft Access that may be of interest to users of those products or developers using those products.
SMOG (Standard Module Object Generation) - Version 2
Programing the Visual Basic Environment (VBE) allows us to access items in our databases that cannot normally be handled as objects, but which normally have to be handled as members of a collection. Not being able to handle such items as objects at design-time leaves the development open to errors that cannot be caught at compile-time, e.g. misspelling of query names, table names and field names. SMOG enables a developer to create objects from such items, e.g. tables, queries and records in (rarely changing) tables. A further gain is a reduction in the amount of code that a developer needs in order to manipulate such items in VBA. Thus instead of specifying the following to open a DAO recordset based on a parameterized query:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set qdf = db.QueryDefs("MyQuery")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset()
rst.AddNew
rst("MyField1") = "My New Value"
rst("MyField2") = 23
....
SMOG allows the developer to refer to the recordset using just the following:
Dim rst As DAO.Recordset
With MyQuery
Set rst = .Query.OpenRecordset()
rst.AddNew
rst(.MyField1.Name) = "My New Value"
rst(.MyField2.Name) = 23
....
SMOG also provides for the creation of a special table which can hold database constants which can then be handled as objects. For example, the table may hold a record whose field name is "Author". With SMOG this can be handled in VBA code in the following manner:
Debug.Print Author 'produces "Alan Cossey"
Author = "Sue Cossey" 'changes the saved value to "Sue Cossey"
i.e. values can be both read and set in code as well as through the supplied GUI.