Mega Code Archive

 
Categories / VisualBasic Script / Access
 

Creating a Single-Field Primary Key with SQL command

Sub SingleField_PKey()     Dim conn As ADODB.Connection     Dim strTable As String     On Error GoTo ErrorHandler     Set conn = CurrentProject.Connection     strTable = "myTable"     conn.Execute "CREATE TABLE " & strTable _         & "(SId INTEGER, " _         & "SName CHAR (30), " _         & "CONSTRAINT idxPrimary PRIMARY KEY " _         & "(SId));"     Application.RefreshDatabaseWindow ExitHere:         conn.Close         Set conn = Nothing         Exit Sub ErrorHandler:         MsgBox Err.Number & ":" & Err.Description         Resume ExitHere End Sub