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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Add a field to a table using VBA 1

Status
Not open for further replies.

maupiti

Programmer
Oct 27, 2003
240
US
Access 2003

Cannot Add a field to a table using VBA.
The table named "Table_Source_1" is already in existence.
The code below has no error message, however it did
not create the field.

///////////////////////////////////////////////

Private Sub Add_A_Field_To_The_Source_Table()
Dim Tdf_Source_Table As TableDef
Dim Field_Done As Field
Dim Dbs As Database

Set Dbs = CurrentDb

Set Tdf_Source_Table = Dbs.CreateTableDef("Table_Source_1")
Set Field_Done = Tdf_Source_Table.CreateField("Done", dbText)
Field_Done.Size = 3

Tdf_Source_Table.Fields.Append Field_Done
Dbs.Close
End Sub
 
You may try this:
CurrentDb.Execute("ALTER TABLE Table_Source_1 ADD COLUMN Done CHAR(3);")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV, and thank you for your help. I got the VBA code above from a Microsoft book "Building Apllications with Microsoft Access 97." Why would it not run ?
 
Passing through VB is not the best way to modify tables unless ur using recordsource.... SQL is more straight forward....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top