>

Name Property

Applies To

Container Object, Database Object, Document Object, Dynaset-Type Recordset Object, Field Object, Group Object, Index Object, Parameter Object, Property Object, QueryDef Object, Recordset Object, Relation Object, Snapshot-Type Recordset Object, Table-Type Recordset Object, TableDef Object, User Object, Workspace Object.

Description

Sets or returns a user-defined name for a data access object. For an object not appended to a collection, this property is read/write.

Settings and Return Values

The setting or return value is a string expression that specifies a name. The name must start with a letter and can contain a maximum of 64 characters. It can include numbers and underscore characters ( _ ) but can't include punctuation or spaces. The data type is String.

Remarks

TableDef and QueryDef objects can't share the same name, nor can User and Group objects.

The Name property of a Recordset object opened using an SQL statement is the first 256 characters of the SQL statement.

You can use an object's Name property with the Dim statement in code to create other instances of the object.

Note

For many of the Database objects, the Name property reflects the name as known to the Database object, as in the name of a TableDef, Field, or QueryDef object. There is no direct link between the name of the Database object and the object variable used to reference it.

The read/write usage of the Name property depends on the type of object it applies to, and whether or not the object is has been appended to a collection.

Object

Usage

Container

Read-only

Database

Read-only

Document

Read-only

Field

Unappended

Read/write

Appended to Index

Read-only

Appended to QueryDef

Read-only

Appended to Recordset

Read-only

Appended to TableDef (native)

Read/write


Object

Usage

Field

Appended to TableDef (linked)

Read-only

Appended to Relation

Read-only

Group

Unappended

Read/write

Appended

Read only

Index

Unappended

Read/write

Appended

Read only

Parameter

Read-only

Property

Unappended

Read/write

Appended

Read-only

Built-in

Read-only

QueryDef

Unappended

Read/write

Temporary

Read-only

Appended

Read/write

Recordset

Read-only

Relation

Unappended

Read/write

Appended

Read-only

TableDef

Read/write

User

Unappended

Read/write

Appended

Read-only

Workspace

Unappended

Read/write

Appended

Read-only


See Also

CreateDatabase Method, CreateField Method, CreateIndex Method, CreateQueryDef Method.

Example

This example creates a TableDef object and then names it Parts ID.


Dim dbsNorthwind As Database, tdfPartsID As TableDef
Set dbsNorthwind =  DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
Set tdfPartsID = dbsNorthwind.CreateTableDef()


tdfPartsID.Name = "Parts ID"
...    ' Create fields.
dbsNorthwind.TableDefs.Append tdfPartsID
Example (Microsoft Access)

The following example creates two new TableDef objects and names them. The name of the first TableDef object is included as an argument to the CreateTableDef method. The name of the second TableDef object is set using the Name property, after the TableDef object has been created.

Note that you must define fields in the table before the TableDef object can be appended to the TableDefs collection.


Sub NameNewTables()
    Dim dbs As Database
    Dim tdfDefinitions As TableDef, tdfSynonyms as TableDef

    ' Return Database variable that points to current database.
    Set dbs = CurrentDb
    ' Create and name TableDef object.
    Set tdfDefinitions = dbs.CreateTableDef("Definitions")
    ' Create second TableDef object.
    Set tdfSynonyms = dbs.CreateTableDef("")
    ' Set Name property for second TableDef object.
    tdfSynonyms.Name = "Synonyms"
    .                            ' Create fields.
    .
    .
    dbs.TableDefs.Append tdfDefinitions
    dbs.TableDefs.Append tdfSynonyms
End Sub
Example (Microsoft Excel)

This example enters in the active cell on Sheet1 the name of the first recordset in the NWINDEX.MDB database.

To create the NWINDEX.MDB database, run the Microsoft Excel example for the CreateDatabase method.


Dim db As Database, td As TableDef
Set db = Workspaces(0).OpenDatabase(Application.Path & "\NWINDEX.MDB")
Set td = db.TableDefs(0)
Sheets("Sheet1").Activate
ActiveCell.Value = td.Name
db.Close