ScotterMonk
09-24-2004, 11:52 PM
Attempting to programmatically (ASP) add an indexed (not key) field to an MS Access 2002 table.
Error I get is:
"Index or primary key cannot contain a Null value"
The funky thing is that I look at the tables (this code is within a loop
that goes thru a few MDB files) and I see it works with one file, adds the
field, index, default value, etc... and then loops to next table, adds the
field, and comes up with the error before adding the index.
SEE DOWN BELOW WHERE I SAY "ERROR IS HERE"
[clip]
set objColumn = server.CreateObject("ADOX.Column")
objColumn.Name = s_new_field_name
objColumn.Type = s_new_field_type
if (s_new_field_size<>"") then objColumn.DefinedSize = s_new_field_size
set objColumn.ParentCatalog=Cat
if (left(s_new_field_name,2)="ID") then
set objIndex = server.CreateObject("ADOX.Index")
'if (s_new_field_required<>"") then objColumn.Properties("Nullable") = true
'if (s_new_field_required<>"") then
objColumn.attributes=s_new_field_required
end if
objColumn.properties("Default")=0
objColumn.properties("Nullable")=true
objTable.Columns.Append objColumn
if (left(s_new_field_name,2)="ID") then
objIndex.NAME = s_new_field_name & "_index"
objIndex.COLUMNS.APPEND(s_new_field_name) '<<<ERROR IS HERE
objIndex.PrimaryKey = false
objIndex.Unique = false
objTable.INDEXES.APPEND(objIndex)
end if
set objColumn=nothing
set objIndex=nothing
[clip]
--
Scotter
Error I get is:
"Index or primary key cannot contain a Null value"
The funky thing is that I look at the tables (this code is within a loop
that goes thru a few MDB files) and I see it works with one file, adds the
field, index, default value, etc... and then loops to next table, adds the
field, and comes up with the error before adding the index.
SEE DOWN BELOW WHERE I SAY "ERROR IS HERE"
[clip]
set objColumn = server.CreateObject("ADOX.Column")
objColumn.Name = s_new_field_name
objColumn.Type = s_new_field_type
if (s_new_field_size<>"") then objColumn.DefinedSize = s_new_field_size
set objColumn.ParentCatalog=Cat
if (left(s_new_field_name,2)="ID") then
set objIndex = server.CreateObject("ADOX.Index")
'if (s_new_field_required<>"") then objColumn.Properties("Nullable") = true
'if (s_new_field_required<>"") then
objColumn.attributes=s_new_field_required
end if
objColumn.properties("Default")=0
objColumn.properties("Nullable")=true
objTable.Columns.Append objColumn
if (left(s_new_field_name,2)="ID") then
objIndex.NAME = s_new_field_name & "_index"
objIndex.COLUMNS.APPEND(s_new_field_name) '<<<ERROR IS HERE
objIndex.PrimaryKey = false
objIndex.Unique = false
objTable.INDEXES.APPEND(objIndex)
end if
set objColumn=nothing
set objIndex=nothing
[clip]
--
Scotter