By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,527 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

copying and changing fields to another table can you change description at this time?

P: n/a
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

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 13 '05 #2

P: n/a
Thanks for your help. I could not find any way to do it and was not
sure if it was my limited exp or it was not a think that could be done
on creation.

btw is there a book that deals with this sort of thing.
Every book I have seen on access either deals with basic forms and
tables or is a reference that only deals with common coding things.

My book is access databases in a nutshell....I find it very good but
some things like this it does not deal with well..

thanks again
jerry

On 23 Jun 2004 14:56:59 -0700, ja******@oakland.edu (James Fortune)
wrote:
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


Nov 13 '05 #3

P: n/a
sparks <sp****@here.com> wrote in message news:<41********************************@4ax.com>. ..
Thanks for your help. I could not find any way to do it and was not
sure if it was my limited exp or it was not a think that could be done
on creation.

btw is there a book that deals with this sort of thing.
Every book I have seen on access either deals with basic forms and
tables or is a reference that only deals with common coding things.

My book is access databases in a nutshell....I find it very good but
some things like this it does not deal with well..

thanks again
jerry


Any author that has written such a book is probably monitoring this
NG. You ought to be able to get some sample code from someone here or
get pointed to a good book. This NG IS the best place to be. A lot
of the information you find here is not in any book yet.

James A. Fortune
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.