"Variable not defined" when specifying field type

G

Guest

I am programmatically creating a new field using this code (per examples in the MS KB):

Set abc = CurrentDb.TableDefs("Table1").CreateField("Field1").Type
abc.Type= dbText

However, the Type property will accept only the numeric constants (10 for dbText in this case) not the literals. Use of "dbText" or even "Text" generates a "Variable not defined" error.

There is no reference for the numeric/literal associations in the help files, so I am left with reverse engineering this by creating a field, then reading its properties to find the numeric constants.

Why is there no literal-to-numeric list in the help files, and how can I enable literal constants?
 
G

Guest

I figured it out - I was missing a reference to DAO. However, I still would like a numeric-to-literal conversion list. In creating an AutoNumber field, the Type = 4 and Attributes = 17. The only way to figure this out was to read the properties of an existing AutoNumber field. I guess that works, but it would still be nice for the help files to provide some real help here.
 
D

Douglas J. Steele

In actual fact, there's no such data type as AutoNumber. It's a Long
Integer, with the AutoIncrement attribute set:

The Access 97 help file includes the following example:

Set tdf = dbs.CreateTableDef("Contacts")
Set fld1 = tdf.CreateField("ContactID", dbLong)
fld1.Attributes = fld1.Attributes + dbAutoIncrField
tdf.Fields.Append fld1

Didn't bother checking if it's still in the Help file for newer versions.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Brian said:
I figured it out - I was missing a reference to DAO. However, I still
would like a numeric-to-literal conversion list. In creating an AutoNumber
field, the Type = 4 and Attributes = 17. The only way to figure this out was
to read the properties of an existing AutoNumber field. I guess that works,
but it would still be nice for the help files to provide some real help
here.for dbText in this case) not the literals. Use of "dbText" or even "Text"
generates a "Variable not defined" error.files, so I am left with reverse engineering this by creating a field, then
reading its properties to find the numeric constants.enable literal constants?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top