How can i programatically check to see if a certain table has a specific field, and if it doesnt, add the field to the table? The field isnt going to have any relationships or indexes, so i'm hoping it will be simple. Thanks for any help.
Are you trying to add a new field or append data to a field. If you want to create a new field you can use .FieldName to test for the fields existance. If you want to append data, you can create a recordset to see if the records already exists, and if not, append.
Well, i got it working pretty well. Now i just need to test if the field is there or not. I noticed that lbigk said i could use .fieldname to test if it is there or not, so i will look into that. Thanks for your help so far!
somting like this should work using DAO
Dim dbs As Database, tdf As TableDef
Dim fld As Field, fldexist As Boolean
Set dbs = CurrentDb
Set tdf = dbs.TableDefs!table1
For Each fld In tdf.Fields
If fld.Name = "test1" Then fldexist = True
Next fld
If fldexist = False Then
Set fld = tdf.CreateField("test1", dbText, 11)
tdf.Fields.Append fld
End If
Set dbs = Nothing
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.