I am trying to create a calculated field in access using VBA. I have other code working for regular field types (Text,Number,etc). When it comes to the calculated field, the field is not added to the access table. I think it has something to do with the expression.
Code:Set db = CurrentDb() ... 'This code works fine and the fields are added to access table For Each strColumn In strColumns Set columnName = xlsht.Cells(1, strColumn) If columnName = "National ID" Then Set columnName = xlsht.Cells(1, "SSN") End If If columnName <> "" Then Set FieldName = tb1.CreateField(columnName, dbText, 150) tb1.Fields.Append FieldName End If Next strColumn ... 'When I try to add calculated Field, it is not added to table fd1 = "Decease?" Set f1 = tb1.CreateField(fd1) f1.Expression = IIf(IsNull([Dt of Death]), 0, IIf([covg elect] = "T", 0, 1)) tb1.Fields.Append f1


Reply With Quote