G
gaugust
I am having a problem assigning properties to a date(ICUdt) and decimal field
(random). I would like to assign a format of "short date" to the date field
and a precision of 18, scale of 18 and decimal places of "auto" to the
decimal field. I tried to assign the "short date" to the date field but it is
not working. Could you please let me know what the syntax is to assign
properties to these two fields. Thanks. Here is my code:
Private Sub cmdCreatecases_Click()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim idx As DAO.Index
Dim prp As DAO.Property
Dim fldControl As DAO.Field
Dim fldICUdt As DAO.Field
Dim fldRandom As DAO.Field
Set dbs = CurrentDb
On Error Resume Next
'Create a table for each case (record) in cases table
'Create the table definition in memory
tablename = "Control1"
Set tdf = dbs.CreateTableDef(tablename)
Set fldControl = tdf.CreateField("Control", dbInteger)
fldControl.Required = True
'Create the Primary Key index using Control
Set idx = tdf.CreateIndex("PrimaryKey")
idx.Primary = True
idx.Fields.Append tdf.CreateField("Control")
idx.Fields.Refresh
'Append the index and refresh
tdf.Indexes.Append idx
tdf.Indexes.Refresh
Set fldICUdt = tdf.CreateField("ICUdt_Con", dbDate)
fldICUdt.Required = False
Set fldRandom = tdf.CreateField("Random", dbDecimal)
fldRandom.Required = True
'Append the fields to the TableDef's Fields collection
tdf.Fields.Append fldControl
tdf.Fields.Append fldICUdt
tdf.Fields.Append fldRandom
'Create a property
Set prp = fldICUdt.CreateProperty("Format", dbText, "Short Date")
'Add the property to the field
fldICUdt.Properties.Append prp
'Append the TableDef to the Database's TableDefs collection
dbs.TableDefs.Append tdf
'Refresh the TableDefs collection
dbs.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set fldControl = Nothing
Set fldICUdt = Nothing
Set fldRandom = Nothing
End Sub
(random). I would like to assign a format of "short date" to the date field
and a precision of 18, scale of 18 and decimal places of "auto" to the
decimal field. I tried to assign the "short date" to the date field but it is
not working. Could you please let me know what the syntax is to assign
properties to these two fields. Thanks. Here is my code:
Private Sub cmdCreatecases_Click()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim idx As DAO.Index
Dim prp As DAO.Property
Dim fldControl As DAO.Field
Dim fldICUdt As DAO.Field
Dim fldRandom As DAO.Field
Set dbs = CurrentDb
On Error Resume Next
'Create a table for each case (record) in cases table
'Create the table definition in memory
tablename = "Control1"
Set tdf = dbs.CreateTableDef(tablename)
Set fldControl = tdf.CreateField("Control", dbInteger)
fldControl.Required = True
'Create the Primary Key index using Control
Set idx = tdf.CreateIndex("PrimaryKey")
idx.Primary = True
idx.Fields.Append tdf.CreateField("Control")
idx.Fields.Refresh
'Append the index and refresh
tdf.Indexes.Append idx
tdf.Indexes.Refresh
Set fldICUdt = tdf.CreateField("ICUdt_Con", dbDate)
fldICUdt.Required = False
Set fldRandom = tdf.CreateField("Random", dbDecimal)
fldRandom.Required = True
'Append the fields to the TableDef's Fields collection
tdf.Fields.Append fldControl
tdf.Fields.Append fldICUdt
tdf.Fields.Append fldRandom
'Create a property
Set prp = fldICUdt.CreateProperty("Format", dbText, "Short Date")
'Add the property to the field
fldICUdt.Properties.Append prp
'Append the TableDef to the Database's TableDefs collection
dbs.TableDefs.Append tdf
'Refresh the TableDefs collection
dbs.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set fldControl = Nothing
Set fldICUdt = Nothing
Set fldRandom = Nothing
End Sub