Show All

I get a "Method or data member not found" message when I try to refer to a table field in code.

Microsoft Access displays this message if you use the . (dot) operator rather than the ! operator to refer directly to a table field. For example, this error is produced by the last line of the following block of Microsoft Visual Basic code:

Dim dbsCurrent As Database
Dim tblTest As TableDef
Dim fldTest As Field

Set dbsCurrent = CurrentDb
Set tblTest = dbsCurrent.TableDefs("Categories")
Set fldTest = tblTest.CategoryID

To correct the problem, replace the . (dot) operator with the ! operator or refer to the field as an element of the Fields collection. You can use either of the following lines of code, although the first might result in faster performance:

Set fldTest = tblTest!CategoryID

Set fldTest = tblTest.Fields("CategoryID")