HandsOn Creating a Single Field Primary

1. Switch to the Visual Basic Editor window and insert a new module.

2. In the module's Code window, enter the SingleField_PKey procedure as shown below.

Sub SingleField_PKey()

Dim conn As ADODB.Connection Dim strTable As String

On Error GoTo ErrorHandler

Part III

Set conn = CurrentProject.Connection strTable = "Supplier3"

conn.Execute "CREATE TABLE " & strTable _ & "(Supplierld INTEGER, " _ & "SupplierName CHAR (30), " _ & "SupplierPhone CHAR (12), " _ & "SupplierCity CHAR (19), " _" & "CONSTRAINT idxPrimary PRIMARY KEY " _ & "(Supplierld));" Application.RefreshDatabaseWindow ExitHere:

conn.Close Set conn = Nothing Exit Sub ErrorHandler:

MsgBox Err.Number & ":" & Err.Description Resume ExitHere

End Sub

Figure 21-3: The result of running the SingleField_PKey procedure in Hands-On 21-4 is a primary key index named idxPrimary based on the SupplierID column.
0 0

Post a comment