|
|
Создание Таблицы "Digits" и заполнение её значениями (DAO)
Private Sub CreateDigitsTable()
Const csTableName$ = "Digits"
Const csFieldName$ = "Digit"
Const ciTotRecords% = 100
Dim tbl As TableDef
Dim idx As index
Dim fld As Field
Dim rst As Recordset
Dim iVal%
On Error Resume Next
CurrentDb.TableDefs.Delete csTableName
Err.Clear
On Error GoTo CreateDigitsTable_Err
Set tbl = CurrentDb.CreateTableDef(csTableName)
With tbl
Set fld = tbl.CreateField(csFieldName, dbLong)
fld.Attributes = dbAutoIncrField
.Fields.Append fld
Set idx = .CreateIndex("Primary Key")
With idx
.Fields.Append .CreateField(csFieldName)
.Unique = True
.Primary = True
End With
.Indexes.Append idx
End With
CurrentDb.TableDefs.Append tbl
Set rst = CurrentDb.OpenRecordset("Digits", dbOpenDynaset)
For iVal = 1 To ciTotRecords
With rst
.AddNew: .Update
End With
Next iVal
CreateDigitsTable_Bye:
On Error Resume Next
Set idx = Nothing: Set tbl = Nothing
rst.Close: Set rst = Nothing
Exit Sub
CreateDigitsTable_Err:
MsgBox "Произошла ошибка при выполнении процедуры [CreateDigitsTable] :" & vbCrLf & _
Err.Description & vbCrLf & "Номер ошибки:" & Err.Number, vbCritical
Resume CreateDigitsTable_Bye
End Sub
|
|