21, Feb, 2019

Connect .mdb database and Insert Data – AutoCAD VBA

autocad vba mdb database

Sample codes – AutoCAD VBA and *.mdb database

  1. Insert data into the table “Table1”

First of all, add the reference (Microsoft ActiveX Data Objects 2.8 Library) to the project – My Auto-CAD Version 2007 – as shown below

This Project assumes, you have data in 3 text boxes and need to insert those into the Table1 & Fields D1, S1 and T2

Code begines

Dim commandstring as string

Dim databasepath as string

databasepath = “E:\DATABASE.mdb”

Dim connection1 As New ADODB.Connection
Dim command1 As New ADODB.Command

commandstring = “INSERT INTO Table1(D1,S1,T2) VALUES(‘” & Me.TextBox1.Text & “‘,'” & CDbl(Me.TextBox2.Text) & “‘,'” & CDbl(Me.TextBox3.Text) & “‘)”

connection1 .Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” &
databasepath & “; Jet OLEDB:Database Password=;”
command1.ActiveConnection = connection1

command1.CommandText = commandstring


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>