CreateField problem

D

dancat

Hello,

I was wondering whether I could take the thread below a step further?

'Adding a new field to a table'
(http://www.msaccessforum.com/t53015-s)

I understand how to amend a certain TableDef to add a new field to a
table. However the CreateField command only seems to set three
properties of the field (name,type,size). What if you wanted to set
values for other properties of the field - for instance 'Default Value'
or LookUp values?

I wanted to do a similar thing to David but looked at it a different
way. Here is what I have done. ie Import a temporary table into the
database and copy the fields over.


public sub install()
dim strpathtb as string
dim db as database
dim tblsource as tabledef
dim fldsource as field
dim fldtarget as field
dim tbltarget as tabledef
strpathtb = \"d:\perfectprintingco\tbprintco.mdb\"

docmd.transferdatabase acexport, \"microsoft access\", strpathtb,
actable, \"dsimport\", \"dsimport\", true
set db = opendatabase(strpathtb)
set tbltarget = db.tabledefs(\"tblstaff\")
set tblsource = db.tabledefs(\"dsimport\")
set fldsource = tblsource.fields(\"position\")
set fldtarget = tbltarget.createfield(fldsource.name)
tbltarget.fields.append fldtarget
tbltarget.fields.refresh

At this point I have imported a new table into the target database and
copied the field over. But I want to make sure that all the properties
of the field are copied over too. I thought maybe somekind of Loop
procedure? It's here that I am having trouble...


'for each fldtarget.properties.item in tbltarget
'fldtarget.properties.item.value = fldsource.properties.item.value
'next
End Sub

Does anyone know what I am trying to do is possible?

ThankYou

Dan
 
D

Douglas J. Steele

If you're copying a field from one table to another, all of the properties
associated with the field should come with it.

It is possible to loop through all of the properties of a field using code
like:

Dim prpCurr As Property

For Each prpCurr in fldSource
Debug.Print prpCurr.Name
Next prpCurr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top