sparks <sp****@here.com> wrote in message news:<bp********************************@4ax.com>. ..
@ I was copying fields from one table to another.
@ IF the var name starts with milk I change it to egg and create it in
@ the destination table.
@ It works fine but I want to copy the description as well.
@
@ Short version :)
@
@ For Each fld In tdf.Fields
@ pos = InStr(fld.Name, "milk")
@ If pos > 0 Then
@ strName = Left(fld.Name, pos - 1) & "egg" &
@ Right(fld.Name, Len(fld.Name) - pos - Len("milk") + 1)
@ Set fldNew = tdf.CreateField(strName, dbInteger)
@ tdff.Fields.Append fldNew
@
@ if I do something like
@ Set fldNew = tdf.CreateField(strName, dbInteger)
@ fldNew.Description = >>>the desctiption of the existing field
@ tdff.Fields.Append fldNew
@
@ this does not work.
@ IS there a way to edit the description when you create the new field?
@ or will I have to loop thru the code again to copy the description?
@
@ thanks big time for any pointers
@
@ jerry
Steve Jorgensen wrote (1999/11/01) answering G. Manuel:
You can only add properties to an object after it is saved, not before. In
this case, you will have to save the tabledef before you can add custom
properties to its controls.
G. Manuel wrote: Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Dim prop As Property
Set db = CurrentDb
' Create a new table
Set tdf = db.CreateTableDef("zzjunk")
' Create one field in the table
Set fld = tdf.CreateField("Field1", dbText, 30)
' Try to set Field Description property - does not exist!
' fld.Properties("Description") = "My Description" ' Error: 3270
Property not found
' Create a new property for the field
Set prop = fld.CreateProperty("MyProp", dbText, "MyProp value")
' The following generates Error 3219. Invalid Operation.
' HELP says either the Property is read-only,
' or the Field does not allow user-defined Properties
fld.Properties.Append prop
fld.Properties.Refresh
' Add the field to the table
tdf.Fields.Append fld
' Add the table to the database
db.TableDefs.Append tdf
db.Close
End Function
P.S., Allen Browne wrote (1997/12/08):
:The trick with the Description property is that if any field does not
:have a Description entered, then the property does not exist, i.e.
:trying to reference it generates an error.
:The basic approach is:
:------------------------------------------------------------------------
:Function ShowDescrip (strTable)
: On Error GoTo Err_ShowDescrip
: Dim db As Database, tdf As TableDef, fld As Field, i As Integer
: Set db = CurrentDB()
: Set tdf = db.tabledefs(strTable)
: Debug.Print "TABLE " & strTable & ": " &
:tdf.Properties("Description")
: For i = 0 To tdf.fields.count - 1
: Set fld = tdf.fields(i)
: Debug.Print fld.Name, fld.Properties("Description")
: Next
:
:Exit_ShowDescrip:
: Exit Function
:Err_ShowDescrip:
: If Err = 3270 Then
: Resume Next
: Else
: MsgBox (Err & ": " & Error$), , "ShowDescrip()"
: End If
:End Function
It looks like looping again is your best option.
James A. Fortune