Tuesday, 18 September 2012

How to connect word document to MS Access database

word is a software which is used to process word but you can save record in access.
Using word for doing this you will have to use control box from Toolbar.
After getting control box, Take control which you want...
I'm using 3 textbox and 1 button in my example

Now double click on your button . VB coding window will appeared.
For database connectivity I have use ADODB class.
you need to  add   a reference of  this class otherwise you can't use this.
for add reference in vb coding window click
Select Microsoft ActiveX Data Object 2.6 Library

Code of Save Button

Private Sub CommandButton1_Click()
    Dim con As New ADODB.Connection
    con.Open ("provider=microsoft.jet.oledb.4.0;data source=bsw.mdb")
    con.Execute "insert into stu values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text   & "')"
    MsgBox "Saved"
End Sub

  • Paste this code on your vb window
  • You need VB install on your System
  • Make your database in MS Access
  • If your database is not in current folder then provide absolute path