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

Deleting a field from a table

Status
Not open for further replies.

Firsttimeprogrammer

Programmer
Feb 10, 2005
8
US
Hi, I'm only new to programming. I want to delete a field and its data from a table. I don't want any other fields affected. I need help writing this code in a module. I'm pretty sure i need to use the TableDef object. Can any one be kind enough to help.

I know how to do this in design or datasheet view, but in this case l have to write the code in a module.
I'm using Access 97.

Thank you.
Kevin
 
You could do it with a TableDef, but you could use a SQL DDL statement instead. It's much easier.
Code:
    DoCmd.RunSQL "ALTER TABLE MyTable DROP COLUMN MyField;"
If your table name and field name are determined dynamically, use a slightly different syntax. Say the table name is in strTableName and the field name is in strFieldName. The code would be:
Code:
    DoCmd.RunSQL "ALTER TABLE " & strTableName & " DROP COLUMN " & strFieldName & ";"
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top