tags:

views:

63

answers:

1

I'd like to append one field property to multiple newly-created fields, like this:

Set Robo0 = RoboCallDB.CreateProperty("Format", dbText, "0")
   With RoboCallDB.TableDefs(sTableName)
   .Fields("Account").Properties.Append Robo0
   .Fields("ServAddrPhone").Properties.Append Robo0
   .Fields("CustWorkPhone").Properties.Append Robo0
   .Fields("SpouseWorkPhone").Properties.Append Robo0
End With

But the code stops at after the first append and gives me Run-time error 3367. ("Cannot append. An object with that name already exists in the collection.")

I end up doing this:

RoboCallDB.TableDefs(sTableName).Fields("Account").Properties.Append & _ 
   RoboCallDB.CreateProperty("Format", dbText, "0")
RoboCallDB.TableDefs(sTableName).Fields("ServAddrPhone").Properties.Append & _
   RoboCallDB.CreateProperty("Format", dbText, "0")
RoboCallDB.TableDefs(sTableName).Fields("CustWorkPhone").Properties.Append & _
   RoboCallDB.CreateProperty("Format", dbText, "0")
RoboCallDB.TableDefs(sTableName).Fields("SpouseWorkPhone").Properties.Append & _
   RoboCallDB.CreateProperty("Format", dbText, "0")

Would someone be able to explain why the first snippet doesn't work, and whether there is a more elegant way than using the second snippet? Thanks in advance!

A: 

I think that in the first version, you are trying to add the same instance of property to several fields, which is not possible.
In the second code sample, you are adding one new instance for each field.
In other words, you create one property for each field, instead of trying to assign the same property to more than one field.

iDevlop