Article ID: 173163
Article Last Modified on 1/20/2007
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"
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"
Additional query words: Reserved Error -1601 there is no message for this error
Keywords: kbbug kberrmsg kbprogramming KB173163