This article was previously published under Q202117
Moderate: Requires basic macro, coding, and interoperability skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Option Explicit
'This Example creates a table with custom identity seed values.
Function CreateNewTable(tName As String, colName As String, _
vSeed As Integer, vInc As Integer)
DoCmd.RunSQL "Create Table " & tName & _
"(CustID Identity(" & vSeed & "," & vInc & "));"
Application.RefreshDatabaseWindow
End Function
?CreateTable("New_tblEmployees","EmpID",1000,5)
Sub Set_IDENTITY_Properties()
'Connects to native Jet 4.0 OLE-DB Provider (MSJETOR40.dll)
Dim strConn As String
Dim adoConn As ADODB.Connection
Dim adoCmd As ADODB.Command
Dim adoTbl As New ADOX.Table
'Use the ADO connection to the database that's already in place
Set adoConn = CurrentProject.Connection
Set adoCmd = New ADODB.Command
'Use a Command Object to issue an SQL statement
With adoCmd
.ActiveConnection = adoConn
.CommandType = adCmdText
.CommandText = "CREATE TABLE New_tblEmployees(EmpID " _
& "IDENTITY(10,5),EmpName CHAR)"
.Execute
'Insert records into the table just created.
.CommandText = "INSERT INTO New_tblEmployees (EmpName) " _
& "SELECT 'Kevin' AS Expr1;"
.Execute
.CommandText = "INSERT INTO New_tblEmployees (EmpName) " _
& "SELECT 'Russ' AS Expr1;"
.Execute
End With
End Sub
Keywords: KB202117, kbprb