Click to See Complete Forum and Search --> : [RESOLVED] How do I add a field to an exsiting Access Table in VBA?


Erik Wiggins
March 19th, 2007, 04:46 AM
OK I've searched and searched for this one and found pleanty of examples but none of them seem to work. This is what I've got


Dim fld As Field
Set fld = CurrentDb.TableDefs("Course Requirements").CreateField("Test")
CurrentDb.TableDefs("Course Requirements").Fields.Append fld
CurrentDb.TableDefs("Course Requirements").Fields.Refresh


Only Problem is when I open Course Requirements there is no new feild named test.

olivthill
March 19th, 2007, 08:24 AM
Your new field must have a type and a length.
For instance, replace the lineSet fld = CurrentDb.TableDefs("Course Requirements").CreateField("Test")bySet fld = CurrentDb.TableDefs("Course Requirements").CreateField("Test", dbText, 40)and it should be working (it is with my Access 2003).

Erik Wiggins
March 27th, 2007, 07:51 AM
Thanks also helps if you have DAO on a higher prioraty then ADO.