ACC97: Transaction in ODBCDirect Workspace Causes Corrupted IndexID: Q173163
|
A Visual Basic for Applications procedure that uses ODBCDirect to create and populate a table in another Microsoft Access database also creates corrupted unique indexes in that table. This behavior occurs if the procedure performs the following steps in sequence:
You are able to make changes to data in other fields.Reserved Error (-1601); there is no message for this error.
If you have already created the table and are unable to enter data because
unique indexes are corrupted, press ESC to cancel the changes to the
record. Then compact the database. After you have compacted the database,
you can make changes to the data in the unique index fields.
There are three methods to prevent the corruption from occurring.
Option Explicit
Sub CreateIndexTrans (strTableName as string, strDSN as string)
Dim Connection1 As Connection, ws As Workspace
On Error GoTo Errorhandler
Set ws = DBEngine.CreateWorkspace _
("TransAct", "Admin", "", dbUseODBC)
Set Connection1 = ws.OpenConnection("Con1", _
dbDriverCompleteRequired, , "ODBC;DSN=" & strDSN)
ws.BeginTrans
Connection1.Execute "CREATE TABLE " & strTableName & _
" (ID INTEGER constraint ID PRIMARY KEY, " & _
"LastName Text (50), FirstName Text (50), keyCode " & _
"Text (10), SSN Text (20))"
'----------- Create Indexes ------------------
Connection1.Execute "CREATE INDEX " & _
"idxLastName ON " & strTableName & " (LastName)"
Connection1.Execute "CREATE UNIQUE INDEX " & _
"idxKeyCode ON " & strTableName & " (KeyCode)"
Connection1.Execute "CREATE UNIQUE INDEX " & _
"idxSSN ON " & strTableName & " (SSN)"
'---------------------------------------------
Connection1.Execute "INSERT INTO " & strTableName & _
" (ID, FirstName, LastName, KeyCode, SSN) " & _
"Values (1, 'Bob', 'Wire', 'ABC','012-34-5678')"
Connection1.Execute "UPDATE " & strTableName & _
" SET FirstName = 'Robert', LastName='Wires', " & _
"KeyCode='A1B1C1', SSN='987-65-4321' WHERE ID = 1"
ws.CommitTrans
Connection1.Close
MsgBox strTableName & " created in other database."
Exit_CreateIndexProblem:
Exit Sub
Errorhandler:
MsgBox CStr(Err) & " " & Err.Description
Resume Exit_CreateIndexProblem
End Sub
CreateIndexTrans "tblIndexTrans", "TestRDO97"
Microsoft has confirmed this to be a problem in Microsoft Access 97. This problem no longer occurs in Microsoft Access 2000.
Option Explicit
Sub CreateIndexProblem(strTableName as string, strDSN as string)
Dim Connection1 As Connection, ws As Workspace
On Error GoTo Errorhandler
Set ws = DBEngine.CreateWorkspace _
("TransAct", "Admin", "", dbUseODBC)
Set Connection1 = ws.OpenConnection("Con1", _
dbDriverCompleteRequired, , "ODBC;DSN=" & strDSN)
ws.BeginTrans
Connection1.Execute "CREATE TABLE " & strTableName & _
" (ID INTEGER Constraint ID PRIMARY KEY, " & _
"LastName Text Constraint idxLastName NOT NULL, " & _
"FirstName Text, " & _
"keyCode Text Constraint idxKeyCode UNIQUE, " & _
"SSN Text Constraint idxSSN UNIQUE)"
Connection1.Execute "INSERT INTO " & strTableName & _
" (ID, FirstName, LastName, KeyCode, SSN) " & _
"Values (1, 'Bob', 'Wire', 'ABC','012-34-5678')"
Connection1.Execute "UPDATE " & strTableName & _
" SET FirstName = 'Robert', LastName='Wires', " & _
"KeyCode='A1B1C1', " & _
"SSN='987-65-4321' WHERE ID = 1"
ws.CommitTrans
Connection1.Close
MsgBox strTableName & " created in other database."
Exit_CreateIndexProblem:
Exit Sub
Errorhandler:
MsgBox CStr(Err) & " " & Err.Description
Resume Exit_CreateIndexProblem
End Sub
CreateIndexProblem "tblTransProblem", "TestRDO97"
For more information about ODBCDirect, search the Help Index for
"ODBCDirect Workspaces."
For more information about setting up ODBC data sources, search the Help
Index for "ODBC, setting up data sources."
For more information about the SQL command CREATE TABLE, search the Help
Index for "CREATE TABLE Statement (Microsoft Jet SQL)."
For more information about the SQL command CREATE INDEX, search the Help
Index for "CREATE INDEX Statement (Microsoft Jet SQL)."
For more information about the SQL command INSERT INTO, search the Help
Index for "INSERT INTO Statement (Microsoft Jet SQL)."
Additional query words:
Keywords : kberrmsg ODBCGen OdbcOthr
Version : WINDOWS:4.0,97
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: August 5, 1999