I need help with the code below. I would like to add 2 extra fields to an existing table in Access.
I am using Access 2007.
First field is the Order Period field. It will be in a text format. Examples of the records in the Order Period field would be jun-12, jul-12, aug-12, may-12 (month-year). I want it to be automatically filled with the current month and current year of the above format when I run the macro.
Second field is the Order Period Date field. It will also be in a text format. Examples of the records here would be 7/1/2012, 8/1/2012, 9/1/2012. It will always be in the 1st of each month in the current year. I want it to be automatically filled with the current month and current year of the above format when I run the macro.
First field will be places in the third column and second field will be in the fourth column.
Can anyone help me fix this code?
Thanks!
Private Sub AddColumn()
Dim curDatabase As Database
Dim tblTooAddToo As TableDef
Dim colFullName1 As Field
Dim colFullName2 As Field
' Get a reference to the current database
Set curDatabase = CurrentDb
' Get a reference to a table named TestTable - NOTE: The table MUST exist
Set tblTooAddToo = curDatabase.TableDefs("Order data")
'define the fields using the CreateField method
' Syntax: .CreateField("FIELD NAME", TYPE, [Length])
' I used the predefined types already in Access
Set colFullName1 = tblTooAddToo.CreateField("Order Period", dbText, 12)
Set colFullName2 = tblTooAddToo.CreateField("Order Period Date", dbDate / Time, 12)
'use the APPEND method to add the fields to the table
With tblTooAddToo.Fields
.Append colFullName1
.Append colFullName2
End With
End Sub
Cross Post here: http://forums.aspfree.com/microsoft-...le-535740.html
Bookmarks