PC Review


Reply
Thread Tools Rate Thread

Add New Field to Existing ACCESS table

 
 
Liz
Guest
Posts: n/a
 
      24th Jun 2004
Is there a way to add a new field (column) to an ACCESS table using VB?
Something comparable to Transact-SQL "Alter Table Add Column ..."?

If so, an example would be extremely helpful.

Thanks in advance!!!!


 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      24th Jun 2004
"Liz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> Is there a way to add a new field (column) to an ACCESS table using
> VB? Something comparable to Transact-SQL "Alter Table Add Column ..."?
>
> If so, an example would be extremely helpful.
>
> Thanks in advance!!!!


You can do it by executing an SQL statement, like this:

CurrentDb.Execute _
"ALTER TABLE ADD COLUMN ...", _
dbFailOnError

You'll want to look at the Jet SQL Reference in the online help to get
the exact syntax for the ALTER TABLE statement. You may need to set a
reference to the Microsoft DAO 3.6 Object Library, in order for the
dbFailOnError constant to be defined.

Or you can do it using the DAO TableDef object:

Dim db As DAO.Database
Dim td As DAO.TableDef

Set db = CurrentDb
Set td = db.TableDefs("MyTable")

With td
.Fields.Append .CreateField("NewField", dbText)
End With

Set td = Nothing
Set db = Nothing

For the above, you definitely need the reference to DAO.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
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
modify field type of existing field in table Kou Vang Microsoft Access VBA Modules 1 16th Dec 2009 01:01 AM
How can I add to an existing field in a table? =?Utf-8?B?Q2hyaXM=?= Microsoft Access Form Coding 1 25th May 2006 05:49 PM
How can I add to an existing field in a table? =?Utf-8?B?Q2hyaXM=?= Microsoft Access Form Coding 1 25th May 2006 04:52 PM
Access 2003: How to add a field to an existing report field list? =?Utf-8?B?aG04NDEwOQ==?= Microsoft Access Reports 2 2nd Feb 2006 12:05 AM
Adding a field to an existing table in Access using VB eroleyikan@hotmail.com Microsoft Access Form Coding 3 4th Mar 2004 11:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:06 AM.