Solved

Word VBA Communicating With Access Database

Posted on 2007-11-26
1
1,265 Views
Last Modified: 2008-02-01
Hello Experts,

I have written VBA code for a Word document that authenticates a user using her username and password. Now i am asked to have the same Word document communicate with an Access database that has images specific to each user. So this is how it goes: user opens Word Document, Word document asks for username and password, if correct, they are are allowed access to the Word document and the image specific to them is automaticallay inserted into the document from the Access database. How do i go about the communication between Word and Access?

Thanks for all your help in Advance.

Tairo
0
Comment
Question by:Tairo
1 Comment
 
LVL 17

Accepted Solution

by:
Shanmuga Sundaram earned 125 total points
ID: 20350303
Go to VB editor from word using Alt+F11

In the vb editor from the insert menu, insert the module.
Then from the tools menu in the references option include "Microsoft Activex Data Objects 2.0 library".
now add the following code. Here I am using the input box to get the user name and password. Assume that the username and password are same. This is used to connect to the access database.

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Public Sub openconnection()
x = InputBox("Please enter the password", "Please enter password")
cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\Shanmuga Sundaram\IMAGES\timesheet\timesheets.mdb;Uid=" & x & ";Pwd=" & x & ";"
End Sub

To insert image from database to word document try the getchunk and putchunk method.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now