Has anyone successfully removed an address from a constituent using VBA? I am tidying up records after an import and am trying to remove lots of empty address fields using a plug-in written in VB6. I'm reasonably experienced in writing plug-ins but CConstitAddresses does not seem to be behaving the same as other RE collections like CConstituentCodes.
The code is:
Dim oRec As CRecord, oConsAdds As CConstitAddressesSet oRec = New CRecordoRec.Init moSCoRec.Load 1605Set oConsAdds = oRec.AddressesoConsAdds.Remove 1,TrueoRec.SaveoRec.CloseDown
Dim oRec As CRecord, oConsAdds As CConstitAddressesSet oRec = New CRecordoRec.Init moSCoRec.Load 1605Set oConsAdds = oRec.AddressesoConsAdds.Remove 1,TrueoRec.SaveoRec.
CloseDown
This should remove the first address from constituent '1605' but nothing happens when the code runs. Has anyone tried something similar with success?
So I am not quite sure this is correct. The line
oConsAdds.Remove 1,True
Will not work as you expect. The 1 is the address id. Alternatively you need to supply the actual CConstitAddress object and that will work.
David
Thanks David,
You are right that in that using the object directly does work. The documentation for VBA says there are two ways to remove a child from a collection, with the collection item number or the object. I have always used the item number on other collections and didn't realise the object removal existed. For those interested the working code is:
Dim oRec As CRecord, oConsAdds As CConstitAddresses, oAddr as CConstitAddressSet oRec = New CRecordoRec.Init moSCoRec.Load 1605Set oConsAdds = oRec.AddressesSet oAddr = oConsAdds.Item(1)oConsAdds.Remove oAddr,TrueoRec.SaveoRec.CloseDown