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
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