A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding a column to an existing table



 
 
Thread Tools Display Modes
  #1  
Old November 16th, 2005, 04:31 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

Is it possible to add a new column to an already existing table? If so how
do you do that?
  #2  
Old November 16th, 2005, 04:47 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

I'm assuming you mean programatically?

Here are two methods ...

Public Sub AddAColumn()

'Using SQL DDL (Data Definition Language)
Dim strSQL As String
strSQL = "ALTER TABLE tblTest ADD COLUMN MyNewTextColumn nvarchar(50)"
CurrentProject.Connection.Execute strSQL, , adCmdText

'Using DAO (Microsoft Data Access Objects)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
Set tdf = db.TableDefs("tblTest")
Set fld = tdf.CreateField("AnotherNewField", dbInteger)
tdf.Fields.Append fld

End Sub

A third alternative is to use ADOX (Microsoft ADO Ext. 2.7 for DDL and
Security). I don't use that much, so I won't attempt to provide an example
myself, but here's a link to the on-line documentation ...

http://msdn.microsoft.com/library/en...ireference.asp

--
Brendan Reynolds


"JOM" wrote in message
...
Is it possible to add a new column to an already existing table? If so
how
do you do that?



  #3  
Old November 16th, 2005, 05:21 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

I think my question was incomplete, what I meant was to add a column other
than going to the table design view to add it

"KARL DEWEY" wrote:

Open the table in design view and add.

"JOM" wrote:

Is it possible to add a new column to an already existing table? If so how
do you do that?

  #4  
Old November 16th, 2005, 05:57 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

On Wed, 16 Nov 2005 08:31:06 -0800, JOM
wrote:

Is it possible to add a new column to an already existing table? If so how
do you do that?


Sure; open the table in design view, add the new field.

If the database is split, you need to do so by opening the backend
database.

John W. Vinson[MVP]
  #5  
Old November 16th, 2005, 07:08 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

On Wed, 16 Nov 2005 09:21:05 -0800, JOM
wrote:

I think my question was incomplete, what I meant was to add a column other
than going to the table design view to add it


Brendan's answers (any of the three) will work in that case.

John W. Vinson[MVP]
  #6  
Old November 16th, 2005, 08:57 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

Thanks I applied that information in a query and it worked!

That helped this is still part of the question. I would like to add 2
columns of table1 and insert that information into the new column of a table2
using a query...

Is that possible!






"Brendan Reynolds" wrote:

I'm assuming you mean programatically?

Here are two methods ...

Public Sub AddAColumn()

'Using SQL DDL (Data Definition Language)
Dim strSQL As String
strSQL = "ALTER TABLE tblTest ADD COLUMN MyNewTextColumn nvarchar(50)"
CurrentProject.Connection.Execute strSQL, , adCmdText

'Using DAO (Microsoft Data Access Objects)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
Set tdf = db.TableDefs("tblTest")
Set fld = tdf.CreateField("AnotherNewField", dbInteger)
tdf.Fields.Append fld

End Sub

A third alternative is to use ADOX (Microsoft ADO Ext. 2.7 for DDL and
Security). I don't use that much, so I won't attempt to provide an example
myself, but here's a link to the on-line documentation ...

http://msdn.microsoft.com/library/en...ireference.asp

--
Brendan Reynolds


"JOM" wrote in message
...
Is it possible to add a new column to an already existing table? If so
how
do you do that?




  #7  
Old November 16th, 2005, 09:29 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

Open the table in design view and add.

"JOM" wrote:

Is it possible to add a new column to an already existing table? If so how
do you do that?

  #8  
Old November 16th, 2005, 10:12 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

Looks like a new question to me, but whatever! :-)

You want to insert the sum of the two fields from which record in table 1
into which record in table 2?

--
Brendan Reynolds

"JOM" wrote in message
...
Thanks I applied that information in a query and it worked!

That helped this is still part of the question. I would like to add 2
columns of table1 and insert that information into the new column of a
table2
using a query...

Is that possible!






"Brendan Reynolds" wrote:

I'm assuming you mean programatically?

Here are two methods ...

Public Sub AddAColumn()

'Using SQL DDL (Data Definition Language)
Dim strSQL As String
strSQL = "ALTER TABLE tblTest ADD COLUMN MyNewTextColumn
nvarchar(50)"
CurrentProject.Connection.Execute strSQL, , adCmdText

'Using DAO (Microsoft Data Access Objects)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
Set tdf = db.TableDefs("tblTest")
Set fld = tdf.CreateField("AnotherNewField", dbInteger)
tdf.Fields.Append fld

End Sub

A third alternative is to use ADOX (Microsoft ADO Ext. 2.7 for DDL and
Security). I don't use that much, so I won't attempt to provide an
example
myself, but here's a link to the on-line documentation ...

http://msdn.microsoft.com/library/en...ireference.asp

--
Brendan Reynolds


"JOM" wrote in message
...
Is it possible to add a new column to an already existing table? If so
how
do you do that?






  #9  
Old November 16th, 2005, 11:34 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

I would like to use a query and not do it by opening the table in design
view...

"John Vinson" wrote:

On Wed, 16 Nov 2005 08:31:06 -0800, JOM
wrote:

Is it possible to add a new column to an already existing table? If so how
do you do that?


Sure; open the table in design view, add the new field.

If the database is split, you need to do so by opening the backend
database.

John W. Vinson[MVP]

  #10  
Old November 17th, 2005, 12:56 AM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Adding a column to an existing table

On Wed, 16 Nov 2005 12:57:27 -0800, JOM
wrote:

That helped this is still part of the question. I would like to add 2
columns of table1 and insert that information into the new column of a table2
using a query...

Is that possible!


In two steps: add the column, then run an Update query updating it to
the sum.

BUT!!!

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.


John W. Vinson[MVP]
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add New Field to DB Karen Database Design 7 October 19th, 2005 08:03 PM
Help again from Ken Snell (Query) Randy Running & Setting Up Queries 22 August 29th, 2005 08:15 PM
Multiple Options Group Patty Stoddard Using Forms 19 August 4th, 2005 02:30 PM
Access combo box-show name, not ID, in table? write on New Users 30 April 30th, 2005 09:11 PM
Table Design A. Williams Database Design 3 April 29th, 2005 07:02 PM


All times are GMT +1. The time now is 11:48 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.