Question MS Word Integration (1 Viewer)

mitch_johnson

Registered User.
Local time
Today, 08:14
Joined
Mar 18, 2009
Messages
40
Hi, Please Be patient with me as i am new to access and still learning the ropes.

what im trying to do is create my database so that when i click a button on my form say named "print invoice" it opens a standard letter and enters the details of the current record i have opened into the relevant places in the letter then print it. (kinda like mail merge but just for one letter at a time and automatic)

If somebody knows how i can do this please could you tell me in easy chunks.

thanks for all your help
 

Mike375

Registered User.
Local time
Tomorrow, 01:14
Joined
Aug 28, 2008
Messages
2,548
You can have Access open a specified Word doc and insert data into Word bookmarks.

But you mention "invoice" so have you considered using a Report.

Anything you do within Access itself such as a Report is always easier and simpler than involving Word (or Excel) with Access. But Word can offer formatting/appearance advantages over a Report depending on what is required.
 

ajetrumpet

Banned
Local time
Today, 10:14
Joined
Jun 22, 2007
Messages
5,638
if you want to do it in word, one way to do it, as mike has suggested, is make a table for the invoice items, put bookmarks in every cell, and a header and footer that you want on it, and then use this code in access:
PHP:
dim wrd as word.application
dim wrdDoc as word.document

set wrdDoc = wrd.documents.open("file name")

wrddoc.Bookmarks("bookmark name").Select
   wrd.Selection.TypeText me.invoiceitem
   etc, etc...
 

mitch_johnson

Registered User.
Local time
Today, 08:14
Joined
Mar 18, 2009
Messages
40
Thanks For Your Reply, Sorry to sound thick but what are bookmarks and how to add them in word to link to my database, thanks
 

Mike375

Registered User.
Local time
Tomorrow, 01:14
Joined
Aug 28, 2008
Messages
2,548
Thanks For Your Reply, Sorry to sound thick but what are bookmarks and how to add them in word to link to my database, thanks

They are like location points.

In Office 2003 and earlier (2007 is probably similar/same) go to Insert and then Bookmark. The bookmark will insert at the cursor point. Access then opens the document and inserts data into the relevant bookmark.

One negative of using bookmarks as opposed to a single record mail merge is bookmarks don't pull together if you have a differen number of lines for address. However, that can be overcome by having more than one Word doc and Access opens the appropriate one depending on the data in the Access record.

I prefer bookmarks but you might find a single record mail merge easier. I think there is something called Super Easy Merge. There are a couple of members use it (Gary Panic I think) and they might respond to a thread on it. It is like a pre package mail merge you can download. It is east to make a query that will select records based on the ID number for the record you have showing on your form.

In the criteria you put

[forms]![YourFormName]![Textbox or field name]
 

NotSoRandomOne

Registered User.
Local time
Today, 10:14
Joined
Sep 15, 2009
Messages
51
...One negative of using bookmarks as opposed to a single record mail merge is bookmarks don't pull together if you have a differen number of lines for address. However, that can be overcome by having more than one Word doc and Access opens the appropriate one depending on the data in the Access record...
Or by having the section in the Word document formatted so that 'returns' create properly justified new lines, and only spitting out new lines (Chr (13)) for each 'line' that exists in the address fields. This entails only having one bookmark, something like "ReturnAddress," rather than a bookmark for each field in the address.

Code:
    If Not IsNull(rs![AddressLine2]) Or rs![AddressLine2] <> "" Then
        tempString = rs![AddressLine1] & Chr(13) & rs![AddressLine2]
    Else
        tempString = rs![AddressLine1]
        End If
    
    city = DLookup("City", "CitiesTable", "ID=" & rs![city])
    state = DLookup("StateInitial", "StatesTable", "ID=" & rs![state])
    
    addressBlock = rs![FirstName] & " " & rs![LastName] & Chr(13) & tempString & Chr(13) & city & ", " & state & "  " & rs![ZipCode]
    
    'Get the Word document:
    Set wordDoc = GetObject("TheDocument.doc")
    wordDoc.Application.Visible = True
    
    'Fill in the address block:
    Dim BMRange As Range
    Set BMRange = wordDoc.Bookmarks("AddressBlock").Range
    BMRange.text = addressBlock
 

Users who are viewing this thread

Top Bottom