PC Review


Reply
Thread Tools Rate Thread

creating fields for table

 
 
Rick
Guest
Posts: n/a
 
      8th Feb 2005
I'm am using:
Dim tdf As DAO.TableDef
Set tdf = db.CreateTableDef("MyNewTable")

I am having trouble creating the fields for "MyNewTable".
I have the fields stored as records in another table. How
do I set them up?

Thanks.
Rick
 
Reply With Quote
 
 
 
 
Roger Carlson
Guest
Posts: n/a
 
      8th Feb 2005
Here's an example of creating a table with one field:

'**************************************************

Sub exaCreateTable()
'DAO DDL example
'demonstrates creating a table, fields, properties
Dim db As DAO.Database
Dim tblNew As DAO.TableDef
Dim fld As DAO.Field

' Create the table and a field
Set db = CurrentDb
Set tblNew = db.CreateTableDef("NewTable")
Set fld = tblNew.CreateField("NewField", dbText, 100)

' Set field properties
fld.AllowZeroLength = True
fld.DefaultValue = "Unknown"
fld.Required = True
fld.ValidationRule = "Like 'A*' or Like 'Unknown'"
fld.ValidationText = "Known value must begin with A"

' Append field to Fields collection
tblNew.Fields.Append fld

' Append table to TableDef collection
db.TableDefs.Append tblNew

End Sub
'**************************************************
Appending the Fields to the Tabledef and the Tabledef to the Tabledefs
Collection are key here.

For more examples, download this file:
http://www.rogersaccesslibrary.com/d...leName=DAO.mdb
And check out the "Chapter 11" and "Chapter 13" modules.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L

"Rick" <(E-Mail Removed)> wrote in message
news:080c01c50df3$9cca3a00$(E-Mail Removed)...
> I'm am using:
> Dim tdf As DAO.TableDef
> Set tdf = db.CreateTableDef("MyNewTable")
>
> I am having trouble creating the fields for "MyNewTable".
> I have the fields stored as records in another table. How
> do I set them up?
>
> Thanks.
> Rick



 
Reply With Quote
 
Alex Dybenko
Guest
Posts: n/a
 
      8th Feb 2005
code below works fine at me:
Set tdf = dbsData.CreateTableDef(rst!UpdateTable)
Set fld = tdf.CreateField(rst!UpdateField,
rst!UpdateValue1, rst!UpdateValue2)
fld.DefaultValue = rst!UpdateValue3
tdf.Fields.Append fld
tdf.Fields.Refresh
dbsData.TableDefs.Append tdf
dbsData.TableDefs.Refresh
Set tdf = Nothing

instead of UpdateTable, UpdateField, UpdateValue1, etc - use your own field
names

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com



"Rick" <(E-Mail Removed)> wrote in message
news:080c01c50df3$9cca3a00$(E-Mail Removed)...
> I'm am using:
> Dim tdf As DAO.TableDef
> Set tdf = db.CreateTableDef("MyNewTable")
>
> I am having trouble creating the fields for "MyNewTable".
> I have the fields stored as records in another table. How
> do I set them up?
>
> Thanks.
> Rick



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating fields from one table into another John Microsoft Access 0 28th Mar 2009 02:15 AM
Creating fields in a new table. =?Utf-8?B?c2pvbmVz?= Microsoft Access VBA Modules 6 30th Mar 2007 09:53 PM
creating fields in a table =?Utf-8?B?Q2FybGVl?= Microsoft Access VBA Modules 4 1st Aug 2004 03:20 AM
Re: Creating fields in an existing table... Dirk Goldgar Microsoft Access VBA Modules 1 21st Jun 2004 09:02 PM
Creating fields in a table Stephen Freeman Microsoft Access Database Table Design 0 25th May 2004 03:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:46 PM.