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

Adding Fields to a Microsoft Access Database using visual basic code

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am presently writing a program that is an upgade. I have added several new field and table to the database structure that I am using. I would like to know how I can add the new fields to existing tables without having to go into physically go into Access or into the Visdata data program.

Thanks,

Cooleen
 
In VB, go to the Help and search for the CreateTableDef Method. It has a great example of how to programatically add a table and fields.
 
Hey this was a program I did once...it's in DAO though.

Private Sub cmdInitialize_Click()
Dim Message, DBPath, DirPath, EmailList As String
Dim rs As Recordset

On Error GoTo ErrorHandler

Set wrkSpace = DBEngine.Workspaces(0)

Set dbSystem = wrkSpace.CreateDatabase("SystemDB.mdb", dbLangGeneral, dbEncrypt)

Set tdfSystem = dbSystem.CreateTableDef("SystemInfo")
With tdfSystem
.Fields.Append .CreateField("DBPath", dbMemo)
.Fields.Append .CreateField("DirPath", dbMemo)
.Fields.Append .CreateField("EmailList", dbMemo)
dbSystem.TableDefs.Append tdfSystem
End With


Delton Phillips
delton.phillips@jamaicanhomes.com
 
Also you can use ALTER TABLE SQL statement. For more info refer to SQL documentation included in Access.
 
VB/MSAccess... hang around. There's more to come....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top