Solved

Word VBA Communicating With Access Database

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

688 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