Solved

Word VBA Communicating With Access Database

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

920 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

12 Experts available now in Live!

Get 1:1 Help Now