Erratic results when updating properties to more than 1 table (1 Viewer)

desmond

Registered User.
Local time
Tomorrow, 01:39
Joined
Dec 8, 2009
Messages
28
I am successfully updating the properties of an access database column, but if I try to update the same properties of another table immediately after, I get erratic results.

Sometimes the result says 'Record deleted'; sometimes the result says 'cannot append. an object with that name already exists in the collection'; sometimes the result says 'object invalid or no longer set'.

This only happens to the second table, the first table is successfully updated.

Here is my code:

Dim dbe As Microsoft.Office.Interop.Access.Dao.DBEngine
Dim dbs As Microsoft.Office.Interop.Access.Dao.Database
Dim fld As dao.Field
Dim prp As dao.Property
Dim prp As dao.Property

'update column to checkbox

dbe = New Microsoft.Office.Interop.Access.Dao.DBEngine()
dbs = dbe.OpenDatabase("C:\MyDB.accdb")
fld = dbs.TableDefs("DBTest").Fields("TestFlag")
prp = fld.CreateProperty("DisplayControl", dbInteger, 106)

Try
fld.Properties.Append(prp)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try

dbs.Close()

'update table 2 column to checkbox

dbe = New Microsoft.Office.Interop.Access.Dao.DBEngine()
dbs = dbe.OpenDatabase("C:\MyDB.accdb")
fld = dbs.TableDefs("DBTest2").Fields("TestFlag")
prp = fld.CreateProperty("DisplayControl", dbInteger, 106)

Try
fld.Properties.Append(prp)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try

dbs.Close()

Has this got something to do with the column in table2 having the same name? I've scoured the net for answers to no avail.

Hoping someone can offer some suggestions.
 

Users who are viewing this thread

Top Bottom