Field properties for primary key and foreign key

  • Thread starter Harold via AccessMonster.com
  • Start date
H

Harold via AccessMonster.com

Do the field properties have to be the same for the primary key and the
foreign key? If I have long Interger on one does the other have to be the
same?
 
H

Harold via AccessMonster.com

Harold said:
Do the field properties have to be the same for the primary key and the
foreign key? If I have long Interger on one does the other have to be the
same?

Also, If I set the primary key to AutoNumber what should the foreign keys
field be? AutoNumber? Number? Text?

Thanks

Harold
 
A

Allen Browne

The AutoNumber is a Long with the dbAutoIncrField flag set.
The matching foreign key should also be a Long.

Presumably you are creating this programmatically, so you will need
something like this:

Sub CreateTableDAO()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set db = CurrentDb()
Set tdf = db.CreateTableDef("Table1")

With tdf
'AutoNumber: Long with the attribute set.
Set fld = .CreateField("ContractorID", dbLong)
fld.Attributes = dbAutoIncrField + dbFixedField
.Fields.Append fld

'Another example: Text field: maximum 30 characters.
Set fld = .CreateField("Surname", dbText, 30)
.Fields.Append fld
End With

db.TableDefs.Append tdf
End Sub
 
P

peregenem

Allen said:
The AutoNumber is a Long with the dbAutoIncrField flag set.

Distinction: Jet's Counter must be incrementing INTEGER. Access's
AutoNumber can incrementing or random and any numeric data type incl
GUID.
 
D

Douglas J. Steele

Distinction: Jet's Counter must be incrementing INTEGER. Access's
AutoNumber can incrementing or random and any numeric data type incl
GUID.

Not so. As you say, an AutoNumber can be incrementing or random, or it can
be a GUID. However, if it's incrementing or random, it can only be a Long
Integer.
 
P

peregenem

Douglas said:
an AutoNumber can be incrementing or random, or it can
be a GUID. However, if it's incrementing or random, it can only be a Long
Integer.

Hey you may be right :)

I remember creating a random currency automnumber in Access2003 but I
can't check now, they took 2003 away! If anyone has it, could they try
it out

If I remember wrong then sorry!
 

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