Access to Word

eddy

Registered User.
Local time
Today, 02:21
Joined
Nov 30, 2005
Messages
23
I have a contract in a Word document. I want to click a button on a form in Access and open up the contract to print but put the client information and items in the appropriate place. Can anyone help or point me to the right documentation to do this?

Thank you.
 
2 options for you

1 bookmarks (check references on this and look up samples)
2 Super easy word funcution - again check references on this site

I have my preference - but you would be best checking yourself
 
Keep all file in Same folder. Link all Table from FE to BE. In Entry Format--NoteSheet (New Scheme) Select Year then click on any Doc, then click on Word Button.
I hope this can help you.
 
Here is a link to Super Easy that Gary mentioned. Scroll about half way down. It is a mail merge system that is set up to be simple to make and can produce just one letter.

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

Bookmarks is the other way. This is more complicated. Search on Access Bookmarks Word or similar.

I know Gary prefers Super Easy, I prefer Bookmarks.

Based on your post I think Super Easy would probably be the way to go.
 
If you want to use the bookmark method, check out:

How to send the current record to Word

Bookmarks are a very helpful tool and quite easy to implement (for people with a bit of VBA experience!)

However, the technique appears to require you to set a reference to the appropriate version of Word. This can be a huge problem if you are trying to distribute the application to many users who are using versions of Office ranging from 2000 - 2007, and sometimes different versions at different workstations on the same network. Even if you know that the user is using Access 2003, for example, you don't really need a call from a client screaming that it stopped working because they bought Access 2007.

Kallal's mail merge uses late binding. This means that you can do the merge regardless of the version of word. I built my own late-binding merge (I don't like some of the aspects of Kallal's) and it works regardless of version of Word.

My question is if anyone knows of a method of using bookmarks that does not require advance knowledge of which version of Word the user will have installed.

SHADOW
 
My question is if anyone knows of a method of using bookmarks that does not require advance knowledge of which version of Word the user will have installed.

SHADOW

The following is the first part of what I use that does not need a reference to MS Word Object Library 11

Dim WordDoc As Object
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open("c:\StoreLetters\" & Format([Forms]![PrintAndClose]![LNameNoDoc]) + ".doc")
WordObj.Visible = True


With WordDoc.Bookmarks
.Item("a1").Range.InsertBefore Nz([Forms]![PrintAndClose]![DateToday], "")

End With




With WordDoc.Bookmarks
.Item("a2").Range.InsertBefore Nz([Forms]![PrintAndClose]![FirstLine], "")
.Item("phone").Range.InsertBefore Nz([Forms]![PrintAndClose]![Phone], "")


End With

DoCmd.OpenForm "LHInsert", acNormal, "", "", acEdit, acNormal

With WordDoc.Bookmarks
.Item("Name").Range.InsertBefore Nz([Forms]![LHInsert]![Name], "")

End With

DoCmd.Close acForm, "LHInsert"
 
Mike:

Wow...that's great! The Microsoft article that HiTech linked uses the office reference. It's great that you have a way to do it without a reference. I have to try that...

Thanks

SHADOW
 
Mike:

Wow...that's great! The Microsoft article that HiTech linked uses the office reference. It's great that you have a way to do it without a reference. I have to try that...

Thanks

SHADOW

SHADOW,

The information to take away from the link I provide is how to use bookmarks. The code can easily be convert to late biding.

During testing, I normally will use early binding (set the reference). This allows the VBA intellisense to work. Once I have the testing completed, I will convert the code to use late biding.

I have found that any Word Automation code can be changed from early binding to late binding by changing just a few lines of code.
 
Last edited:
I like the Bookmark system because I do a fair bit while the doc is open.

SaveAs with date/time and type of letter and client name in the file.

Copy the doc and open a new record in a Many table and paste it to the memo field.

Open a new record on another Many table and insert the doc name so as it can be opened from a tablular form.

I am sure you can do all that with mail merge but I have never been dowm the mail merge road to far.

The Bookmark system is also good for small mail merge where you run from a form and with the form taken to GoToNextRecord etc. Everything is in the order you see. Also good if there might be a few versions of a letter for different categories of people such as occupation class. I don't how many you could do that way before memory ran out as you opening and closing Word everytime.

I also find that a lot of people like that system because they can physically see it all moving from record to record.

Here is similar I have for Excel

Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\" & Format(Range("E25") + ".doc"))
WordObj.Visible = True




With WordDoc.Bookmarks
.Item("a2").Range.InsertBefore Worksheets("Sheet1").Range("A" & "" & ActiveCell.Value).Value
.Item("a3").Range.InsertBefore Worksheets("Sheet1").Range("B" & "" & ActiveCell.Value).Value
.Item("name").Range.InsertBefore Worksheets("Sheet1").Range("C" & "" & ActiveCell.Value).Value
.Item("phone").Range.InsertBefore Worksheets("Sheet1").Range("D" & "" & ActiveCell.Value).Value

End With



Range("L1") = Range("A" & "" & ("E1"))

ActiveCell.Value = Range("G1")

Range("G1") = Blank

Call Macro14

WordDoc.SaveAs ("c:\TestExcel2\" & Format(Range("A3")) + " " & Format(Now, "YYYY-MM-DD") + " " & Format(Now, "hh-mm-ss"))
 
SHADOW,

The information to take away from the link I provide is how to use bookmarks. The code can easily be convert to late biding.

During testing, I normally will use early binding (set the reference). This allows the VBA intellisense to work. Once I have the testing completed, I will convert the code to use late biding.

I have found that any Word Automation code can be changed from early binding to late binding by changing just a few lines of code.

That makes sense. I've always wondered why people would rather set a reference rather than use late binding. I still wonder why all the Microsoft examples use the early binding with all its troubles...

Thanks!

SHADOW
 
The early binding vs late, at least the way I do it, has some differences with Bookmarks for when you want Select/Copy and so on the.

The late bind need [ not the I beam type.

Word also closes much slower.

Although with early bind I don't have the bookmarks wiped out as I think I read in HiTechCoach's link

Shadow, here is some copy type stuff you can include in the above code. These are snippets because as you can see the last copy would wipe out the first:D

Dim RNGbookmarks As Object

With WordDoc.Bookmarks

Set RNGbookmarks = WordObj.ActiveDocument.Range( _
Start:=WordObj.ActiveDocument.Bookmarks("Name").Range.Start, _
End:=WordObj.ActiveDocument.Bookmarks("a2").Range.End)
End With
RNGbookmarks.Select
With WordDoc.Bookmarks
RNGbookmarks.Copy


End With

With WordDoc.Bookmarks
.Item("a2").Range.Select


End With



With WordDoc.Bookmarks
.Item("a2").Range.Copy


End With

With WordDoc.Bookmarks
.Item("a7").Range.Paste


End With
 
The early binding vs late, at least the way I do it, has some differences with Bookmarks for when you want Select/Copy and so on the.

The late bind need [ not the I beam type.

Word also closes much slower.

Although with early bind I don't have the bookmarks wiped out as I think I read in HiTechCoach's link

Shadow, here is some copy type stuff you can include in the above code. These are snippets because as you can see the last copy would wipe out the first:D

Dim RNGbookmarks As Object

With WordDoc.Bookmarks

Set RNGbookmarks = WordObj.ActiveDocument.Range( _
Start:=WordObj.ActiveDocument.Bookmarks("Name").Range.Start, _
End:=WordObj.ActiveDocument.Bookmarks("a2").Range.End)
End With
RNGbookmarks.Select
With WordDoc.Bookmarks
RNGbookmarks.Copy


End With

With WordDoc.Bookmarks
.Item("a2").Range.Select


End With



With WordDoc.Bookmarks
.Item("a2").Range.Copy


End With

With WordDoc.Bookmarks
.Item("a7").Range.Paste


End With

My problem with your code is that it doesn't replace the bookmark text (unless I'm not supposed to use text for bookmarks) because if uses the InsertBefore
 
I close without saving.

My first part is

Forms!PrintAndClose!LetterName = ("" + Format(Now, "YYYY-MM-DD") + " " & Format(Now, "hh-mm-ss") + " " & ([Forms]![PrintAndClose]![CLSurname]) + " " & "Letter 1" + ".doc")

I have that so the letter can be opened at any stage for reference, reprinting etc

The comes

WordDoc.SaveAs ("c:\StoreLetters\" & Format([Forms]![PrintAndClose]![LetterName]))

The template doc is closed with out saving
 
I close without saving.

My first part is

Forms!PrintAndClose!LetterName = ("" + Format(Now, "YYYY-MM-DD") + " " & Format(Now, "hh-mm-ss") + " " & ([Forms]![PrintAndClose]![CLSurname]) + " " & "Letter 1" + ".doc")

I have that so the letter can be opened at any stage for reference, reprinting etc

The comes

WordDoc.SaveAs ("c:\StoreLetters\" & Format([Forms]![PrintAndClose]![LetterName]))

The template doc is closed with out saving

Great idea...I was wondering about that but I assumed that you relied on the user to save as rather than having the code do it.
 
PS,

For what I give to people I go one step further as I have had a couple of intances where the Doc has saved on close.

I have the templates in two folders, one being being a backup for want of a better word.

At the start of the code I copy the template from the second folder and over ride the template that is used.

I close with

WordDoc.Close
Set WordDoc = Nothing

WordObj.Quit

That seems to woerk well and has no problems with Scansoft.
 
Since we are giving Access/Word a workout:D and also have HiTechCoach's attention:)

This is handy to open docs from a tabular form. Put it OnClick. It will set the address and open it

Forms!ln!Command5.HyperlinkAddress = ("C:\StoreLetters\" & Format([Forms]![ln]![LNameNoDoc]) + ".doc")

I did that becuase I have not found a relaible way to open Word in Vista where it is maximised.
 
That makes sense. I've always wondered why people would rather set a reference rather than use late binding. I still wonder why all the Microsoft examples use the early binding with all its troubles...

Thanks!

SHADOW

SHADOW,

Late biding is a lot slower. I only use late binding in for apps where I do not have control over mixed versions of office. So early biding works great and is faster. If I have a choice, I would use early binding.


I urge all my clients to NOT mix versions of Office. IMHO, the problem with early binding "troubles" is cayuse by not having a standard where all user have the same software. Having mixed versions of Office in use causes other issues beside the "biding" issue.

This may be helpful:

Late Binding in Microsoft Access
 

Users who are viewing this thread

Back
Top Bottom