Application.CodeDb (Access)
You can use the CodeDb method in a code module to determine the name of the Database object that refers to the database in which code is currently running. Use the CodeDb method to access Data Access Objects (DAO) that are part of a library database.
For example, you can use the CodeDb method in a module in a library database to create a Database object referring to the library database. You can then open a recordset based on a table in the library database.
Function GetErrorString(ByVal intError As Integer) As String
Dim dbs As Database, rst As RecordSet
' Variable refers to database where code is running.
Set dbs = CodeDb
' Create table-type Recordset object.
Set rst = dbs.OpenRecordSet("Errors", dbOpenTable)
' Set index to primary key (ErrorID field).
rst.Index = "PrimaryKey"
' Find error number passed to GetErrorString function.
rst.Seek "=", intError
' Return associated error message.
GetErrorString = rst.Fields!ErrorData.Value
rst.Close
End Function