Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Open word document from inside a database and populate word doc with some data

Hi
I have a customer management database I have written in Access 2007.  I would like to be able to click on a button when in the customer contact form to open a word document template and populate the document with the name and address details of the customer.

I have created the button, with a clik event to look for and open the relevent word document.  This works but I am not sure how to setup my word document with fields that access can pass data to.

Anyone have this working or know how to set u p the word document for update ?

Below is my VBA code for the open word document button (test code no real document or fields to be updated are listed )


Dim filepath As String
Dim oApp As Object

'Path to the word documentto use
filepath = "c:\text.doc"
'
If IsNull(filepath) Or filepath = "" Then
        MsgBox "Document not found - please check"
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True

'Open the Document
oApp.Documents.Open FileName:=filepath
' specify the fields to be updated (commented out here)
' with doc '.FormFields("fldCountry").Result = Me!Country
'.Visible = True
'.Activate
'End With
End If
'
End Sub

Open in new window

0
ianLMurdoch
Asked:
ianLMurdoch
1 Solution
 
GrahamSkanRetiredCommented:
If necessary, set the Word Option in the 'Popular' set to show the Developer tab.

In the Controls group of that tab, use the drop-down of the lower right-hand button to show 'Legacy Forms'. Clicking the top left-hand button will put a forms-type textbox at the selection point.

To name the field. right-click on it and select properties. Change its bookmark name to 'fldCountry' or whatever is appropriate.

Don't forget to protect the document for filling in forms.

If you uncomment your code, you would have to find  set the doc object, so:

Set doc = oApp.Documents.Open( FileName:=filepath)
0
 
cquinnCommented:
The easiest way is to set bookmarks in the word document, then populate these in your routine

Another way is to write the data to a file and use this as the source data for a mailmerge
0
 
ianLMurdochAuthor Commented:
Thanks worked like a dream, I could not find that bit of information anywhere.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now