?
Solved

Word VBA Communicating With Access Database

Posted on 2007-11-26
1
Medium Priority
?
1,272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
Shanmuga Sundaram earned 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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