Solved

Word VBA Communicating With Access Database

Posted on 2007-11-26
1
1,269 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

860 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