"Bob Darlington" <bo*@dpcmanAX.com.auwrote in message
news:47***********************@news.optusnet.com.a u...
I'm using the following code to try to change a caption property for a
field in a table.
Dim dbs As Database, fld As Field, fFormat As Property
Set dbs = OpenDatabase(CurrentDataFile)
Set fld = dbs.TableDefs(tblName).Fields(fldName)
Set fFormat = fld.CreateProperty("Caption", dbText, strCaption)
fld.Properties.Append fFormat
Each time it's generating error 3367 - "Cannot Append. An object with that
name already exists".
It doesn't matter what strCaption I enter, the same message appears.
I'm using Access 2002.
Any ideas welcome.
--
Bob Darlington
Brisbane
This function first tries to set an already existing property, and if an
error 3270 (property not found) occurs, it appends the new property to the
collection. Paste it into a standard module:
''' BEGIN CODE '''
Sub SetObjProperty(pObject As Object, pProperty As String, pType As Integer,
pValue As Variant)
Const PROPERTY_NOT_FOUND As Long = 3270
Dim prp As Property
'
On Error GoTo SetObjProperty_Err
'
pObject.Properties(pProperty) = pValue
pObject.Properties.Refresh
SetObjProperty_Exit:
Set prp = Nothing
Exit Sub
SetObjProperty_Err:
If Err.Number = PROPERTY_NOT_FOUND Then
With pObject
Set prp = .CreateProperty(pProperty, pType, pValue)
.Properties.Append prp
.Properties.Refresh
End With
Resume SetObjProperty_Exit
Else
MsgBox Err.Number & ": " & Err.Description, vbCritical,
"SetObjProperty"
Resume SetObjProperty_Exit
End If
End Sub
''' END CODE '''
Use it like this:
SetObjProperty fld, "Caption", dbText, strCaption