WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Access

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Adding Fields to an Existing Access Table


Winbatch Version: 2005E -- Script By Jay Alverson

#DefineFunction CreateAndAppendField(tdf, FieldName, FieldType, FieldLength)
   fld = tdf.CreateField(FieldName, FieldType, FieldLength)
   If FieldType == 10 || FieldType == 12 Then fld.AllowZeroLength = ObjectType("BOOL", -1)
   tdf.Fields.Append(fld)
   ObjectClose(fld)
   Return
#EndFunction

dbText = 10
dbname = "C:\Data\Access\Winbatch DAO Test.mdb"

Access = ObjectOpen("Access.Application")
Access.OpenCurrentDatabase(dbname)
Access.Visible = @TRUE
db = Access.CurrentDb

MyTable = db.tabledefs("Copy Of Employees")  ; use a copy of existing table for testing...

Message("Debug", MyTable.name)

CreateAndAppendField(MyTable, "New Field", dbText, 10)

MyTable = 0
Access = 0

Exit

Article ID:   W17138
File Created: 2007:07:03:14:28:26
Last Updated: 2007:07:03:14:28:26