|
Function ChangeSeed(strTbl As String, strCol As String, lngSeed As Long) As Boolean
'清空表全部记录后重置自动编号起始值
'You must pass the following variables to this function.
'strTbl:包含自动编号字段的表
'strCol:表中自动编号的字段名
'lngSeed:新自动编号的起始值
'必须同时引用 Microsoft ActiveX Data Objects 2.x 和 Microsoft ADO Ext 2.x for DDL and Security Libraries(其中 2.x 是指 2.1 或更高版本)
Dim cnn As ADODB.Connection
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column
DoCmd.RunSQL "Delete * FROM " & strTbl & ""
Set cnn = CurrentProject.Connection
cat.ActiveConnection = cnn
Set col = cat.Tables(strTbl).Columns(strCol)
col.Properties("Seed") = lngSeed
cat.Tables(strTbl).Columns.Refresh
If col.Properties("seed") = lngSeed Then
ChangeSeed = True
Else
ChangeSeed = False
End If
Set col = Nothing
Set cat = Nothing
Set cnn = Nothing
End Function
|
|