How to Add Fields to a Table in Access with Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Add Fields to a Table in Access with Visual Basic
Learn how to add fields to a table in Access using VB.NET. (Jupiterimages/ Images)

Knowing how to add new fields to a Microsoft Office Access database table using Visual Basic.NET (VB.NET) can save you time when you need to alter a table. Access is a relational database management system used to design local databases. VB.NET is an object-oriented computer programming language commonly used by programmers for its ease of use. A table is used to store data using columns and rows similar to a spreadsheet.

Skill level:

Other People Are Reading

Things you need

  • Microsoft Visual Basic Express

Show MoreHide


  1. 1

    Open Microsoft Visual Basic Express, and click "New Project..." in the left pane of your screen. Double-click "Console Application." Press "Ctrl" and "A" and then press "Delete" to remove the current code.

  2. 2

    Copy and paste the following code to your "Module1.vb" module to execute a query and add two fields to the "Products" table in the Northwind database.

    Imports System.Data.OleDb

    Module Module 1

    Sub Main()
        Dim northwindConn As OleDbConnection
        Dim sqlComm As OleDbCommand
        Dim strSQL As String
        northwindConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;")
        strSQL = "ALTER TABLE Products " & _
       "ADD COLUMN Product_I Text (30), Product_II Text (30);"
        sqlComm = New OleDbCommand(strSQL, northwindConn)
        MsgBox("Added two fields successfully to the Products table.")
    End Sub

    End Module

  3. 3

    Edit the following line of code and type the path to your database:

    OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;")

    Press "F5" to run your program.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.