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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding a Field to a Table using code.



 
 
Thread Tools Display Modes
  #1  
Old May 26th, 2004, 02:41 PM
Luis Medina
external usenet poster
 
Posts: n/a
Default Adding a Field to a Table using code.

Does anyone know how to add or delete a field from a table using VBA?
  #2  
Old May 26th, 2004, 03:48 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default Adding a Field to a Table using code.

Method 1: DDL
Execute a query statement such as:
"ALTER TABLE MyTable ADD COLUMN MyColumn TEST;"
"ALTER TABLE MyTable DROP COLUMN MyColumn;"

Method 2: DAO
Use CreateField() and then Append to the Fields collection of the TableDef.
Delete the Field from the Fields collection of the TableDef

Method 3: ADOX
Declare a new ADOX.Column, and Append to the Columns of the Table.


Use method 1 for a quick and simple approach.

Use method 2 if you want fine control over the properties of the new field.

Use method 3 if you are a maschochist. (ADOX is very buggy, with different
bugs in different versions so you never know what you will end up with.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Luis Medina" wrote in message
...
Does anyone know how to add or delete a field from a table using VBA?



  #3  
Old May 26th, 2004, 04:36 PM
Luis Medina
external usenet poster
 
Posts: n/a
Default Adding a Field to a Table using code.

Thanks for your help.
 




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


All times are GMT +1. The time now is 11:49 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.