I repetitively create Access Tables with the same fields and field properties. I have been manually creating the table including field names, data types, and individual field properties and then automate the Table load from data in Excel.
When I started, I did not anticipate how useful and efficient this would be. The most time consuming step in this activity is formating the table in Design View. So I want to automate this step in Access VBA and have a working program listed below.
My problem is the below code only defines the Field Name and Data Type. I can't find information on how to change the field properties in VBA. Specifically, I want to set the following field properties:
"DateD": Format to "Short Date"
"Num1" and "Num2: Field Properties to:
Field Size: Double
Format: "Standard" or "Percent"
Decimal Places: 0,1, 2, etc.
Manually, I can do this in design view. How do I set the field properties in Access VBA?
Thank you.
Sub CreateTable()
Dim myTable As TableDef
Set myTable = CurrentDb.CreateTableDef("TestTable")
myTable.Fields.Append myTable.CreateField("DateD", dbDate)
myTable.Fields.Append myTable.CreateField("Description", dbText)
myTable.Fields.Append myTable.CreateField("Num1", dbDouble)
myTable.Fields.Append myTable.CreateField("Num2", dbDouble)
CurrentDb.TableDefs.Append myTable
Application.RefreshDatabaseWindow
End Sub