Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed with TableDef

Status
Not open for further replies.

JasonPurdueEE

Technical User
May 21, 2002
131
US
Hello. I had to change some code when we upgraded to Access 2K (from Access 97). the only bit I cant figure out is my table def. it will run, but it will not create the fields. heres the relivant code:


**************************************************
Dim dbs As Database, tdf As TableDef, tdf2 As TableDef, fld As Field, fld2 as Field

Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("workpack")

Set fld = tdf.CreateField("PWR", dbText, 20)
tdf.Fields.Append fld



Set tdf2 = dbs.CreateTableDef("workpack")

Set fld2 = tdf2.CreateField("Phase", dbLong, 20)
tdf2.Fields.Append fld2

**************************************************

the table I want appended is "workpack"
the fields I want added are "PWR" and "Phase"

Anybody see where I'm going wrong here? Thanks in advance.

JASON
 
^bump^

this is really driving me nuts. anybody wanna nudge me in the right direction please?
 
Hi Jason!

You say this will run. What are the exact results you get when you run this code. Is the table created? Does it have any fields, if so which field does it have?

Jeff Bridgham
bridgham@purdue.edu
 
Hi again!

Sorry Jason, I forgot to ask one question. You say this is all of the relevant code, but I don't see where you are appending the tabledef to the tabledefs collection. Did you just not post that part or is that the problem?

Jeff Bridgham Jeff Bridgham
bridgham@purdue.edu
 
Jeff,
Hello fellow Boilermaker! Thanks for the replies. For clarification, this is appending a pre-existing table. The code will execute without giving me any trouble, but it will not append the two fields onto it. Because its not adding the 2 additional fields, the rest of my code doesnt function correctly.



About your comment on appending to the tabledefs collection, is there something more than:

tdf.Fields.Append fld

that I need to do to make it append?
 
Hey Jason!

I figured with your handle that you were probably somewhere on campus. Try your code like this:

Dim dbs As Database
Dim tdf As TableDef
Dim fld As Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs("testtable")

Set fld = tdf.CreateField("PWR", dbText, 20)
tdf.Fields.Append fld

Set fld = tdf.CreateField("Phase", dbLong, 20)
tdf.Fields.Append fld

Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top