In this article I will explain how you can add fields to a table in an access database using VBA.
If the database does not contain any tables, you can use the topic covered in the article below to create tables for it:
It will be assumed that the access database has a table with the name “MyTable1”.
The code below adds a field to the table “MyTable1” with the name “NewField” of the “CHAR” type:
DoCmd.RunSQL ( _
"ALTER TABLE MyTable1 ADD COLUMN NewFiel2d CHAR")
For more information about the different fields types please see the link below:
Note: Attempting to add a field that already exists will result in a runtime error. A good idea would be to check if the field exists before attempting to add it.
You can download the file and code used in this article from the link below:
Note: Although the code was written in the Excel VBA Editor, it can be written in any other office application.
If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website www.software-solutions-online.com