Latest topics
Statistics
We have 12 registered usersThe newest registered user is reagkla
Our users have posted a total of 41 messages in 35 subjects
Who is online?
In total there are 2 users online :: 0 Registered, 0 Hidden and 2 Guests None
Most users ever online was 108 on Mon Sep 01, 2008 4:48 pm
MS-Access. Create a new autonumber field in existing table.
General Forum :: Top :: VBA
Page 1 of 1
MS-Access. Create a new autonumber field in existing table.
Sub CreateNewAutonumberfield()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index
Dim rel As DAO.Relation
Set db = CurrentDb
On Error Resume Next
'********************************************
' Create new field ID2 of table Table1
Set tdf = db.TableDefs("T_AdjustCntlRecord")
Set fld = tdf.CreateField("ID2", dbLong)
SetPro fld, "Attributes", dbLong, 17
tdf.Fields.Append fld
SetPro fld, "AllowZeroLength", dbBoolean, False
SetPro fld, "DefaultValue", dbText, ""
SetPro fld, "OrdinalPosition", dbLong, 1
SetPro fld, "Required", dbBoolean, False
' create index ID2 of table Table1
Set tdf = db.TableDefs("T_AdjustCntlRecord")
Set idx = tdf.CreateIndex("ID2")
Set fld = idx.CreateField("ID2")
idx.Fields.Append fld
tdf.Indexes.Append idx
End Sub
Private Sub SetPro(o As Object, s As String, t As DataTypeEnum, v As Variant)
'Set the properties
On Error GoTo Problems
o.Properties(s) = v
Exit Sub
Problems:
If Err = 3270 Then
o.Properties.Append o.CreateProperty(s, t, v)
Resume ProblemsX
End If
On Error GoTo 0
Resume
ProblemsX:
End Sub
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index
Dim rel As DAO.Relation
Set db = CurrentDb
On Error Resume Next
'********************************************
' Create new field ID2 of table Table1
Set tdf = db.TableDefs("T_AdjustCntlRecord")
Set fld = tdf.CreateField("ID2", dbLong)
SetPro fld, "Attributes", dbLong, 17
tdf.Fields.Append fld
SetPro fld, "AllowZeroLength", dbBoolean, False
SetPro fld, "DefaultValue", dbText, ""
SetPro fld, "OrdinalPosition", dbLong, 1
SetPro fld, "Required", dbBoolean, False
' create index ID2 of table Table1
Set tdf = db.TableDefs("T_AdjustCntlRecord")
Set idx = tdf.CreateIndex("ID2")
Set fld = idx.CreateField("ID2")
idx.Fields.Append fld
tdf.Indexes.Append idx
End Sub
Private Sub SetPro(o As Object, s As String, t As DataTypeEnum, v As Variant)
'Set the properties
On Error GoTo Problems
o.Properties(s) = v
Exit Sub
Problems:
If Err = 3270 Then
o.Properties.Append o.CreateProperty(s, t, v)
Resume ProblemsX
End If
On Error GoTo 0
Resume
ProblemsX:
End Sub
Similar topics
» How to create an alternate Microsoft Access switchboard form
» How to simplify making a Microsoft Access schema.ini based on a table
» How to simplify making a Microsoft Access schema.ini based on a table
General Forum :: Top :: VBA
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Wed Feb 19, 2014 5:43 am by winnisab
» женская гинекология
Tue Aug 02, 2011 2:42 pm by Guest
» When the first Whirlpool Duet album was released in December 2001
Sun Jul 31, 2011 10:46 pm by Guest
» tsunade porn hentai tsunade porn manga
Sat Jul 30, 2011 7:06 pm by Guest
» How to Find The Best Places to Use Your Metal Detector
Sat May 28, 2011 5:47 am by BobKing1
» How to play Facebook MyZoo
Fri Aug 14, 2009 6:39 am by Dan
» How to create an alternate Microsoft Access switchboard form
Fri Aug 14, 2009 6:39 am by Dan
» How to simplify making a Microsoft Access schema.ini based on a table
Fri Aug 14, 2009 6:38 am by Dan
» How to Make Do Without a Coffee Filter
Fri Aug 14, 2009 6:38 am by Dan