[DB-SIG] Why does Autoincrement column require a value???

Theresa_Stadheim@datacard.com Theresa_Stadheim@datacard.com
Fri, 12 Oct 2001 11:59:16 -0500


I created some Python code to create a Primary Key in an Access datatabase,
setting the AutoIncrement property to True.  I thought an AutoIncrement
field would increment by itself, but for some reason when I run the script,
it complains that my Primary Key field is Null.  Anybody know what I can do
about this?

Here is the error message:
Traceback (most recent call last):
  File "C:\SmartCard\DC9KParser\Parse9k.py", line 347, in ?
    parse(fileName, configFile, AccessDataOutput.AccessDataOutput())
  File "C:\SmartCard\DC9KParser\Parse9k.py", line 328, in parse
    out.handleCard(recordNumber, fields)
  File "C:\SmartCard\DC9KParser\AccessDataOutput.py", line 204, in
handleCard
    self.rs.Update()
  File "<COMObject ADODB.Recordset>", line 2, in Update
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft
JET Database Engine', "The field 'Cards.IDWAutoNumber' cannot contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.", None, 5003000, -2147217887), None)


And here is the code that makes the primary key:

          # new stuff that doesn't work
          # interpreter keeps insisting I need a value for IDWAutoNumber
          # I don't know what kind of value it is looking for and/or how to
set a value
          oColumn = win32com.client.Dispatch("ADOX.Column")
          oKey = win32com.client.Dispatch("ADOX.Key")

          oColumn.Name = "IDWAutoNumber"
          oColumn.ParentCatalog = catalog
          oColumn.Properties("Autoincrement").Value = 1
          table.Columns.Append("IDWAutoNumber", adInteger)
          oKey.Name = "PrimaryKey"
          oKey.Type = 1 #win32.com.client.constants.adKeyPrimary
          oKey.RelatedTable = "Cards"
          oKey.Columns.append("IDWAutoNumber", adInteger)
          table.Keys.append(oKey)

Thanks,
Theresa