Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Records to Word Table

Status
Not open for further replies.

jmbcreative

Technical User
Jan 30, 2006
58
US
Okay. My task is simple. I want to export a report into a word document keeping the same graphical layout as the report. Seeing as how Access and Word are from the same company, and even the same package of software, this should be no problem, right? Big Fat WRONG and I have found plenty of people as frusterated as I am with this. So, I have found an alternative. I created a word document template with bookmarks. I also created a form(don't know any better way) with a command button. this button's click event runs the following code;

******************
Private Sub Command27_Click()
Dim objWord As Object


' Open Microsoft Word using automation
Set objWord = New Word.Application


objWord.Documents.ADD "C:\Documents and Settings\ob264c\My Documents\Database\HardwareBase1.dot"
objWord.Visible = True


' The following code is generated from your Access form while it is
' manipulating an instance of Word.
' So, while it looks somewhat like VBA, it's really Word VBA.


If objWord.ActiveDocument.Bookmarks.Exists("System") = True Then
objWord.ActiveDocument.Bookmarks("System").Range.Text = Me!System
End If

If objWord.ActiveDocument.Bookmarks.Exists("MemorySize") = True Then
objWord.ActiveDocument.Bookmarks("MemorySize").Range.Text = Me!MemorySize
End If



WordObj.ActiveDocument.Close SaveChanges:=wdSaveChanges

' Quit Microsoft Word and release the object variable.
WordObj.Quit
Set WordObj = Nothing

End Sub

**********************
This opens up a word document, references the template and inserts the fields from the active record into the bookmarks of the word document. I reduced the code down a bit. There are actually about five more bookmarks and fields. There are three issues that I am having;

1) When one of the fields is null it jams up and requests a debug.

2) I need to insert data from the entire table of about 1600 records.

Any Ideas?
 
I actually just found the easiest way to do this is to use mail merge within Word.
 
An other alternative is to use OfficeLink in the Acces Menu (choose option Publish It With Microsoft Word). Turns an Access report into a need document with same layout.

Pampers [afro]
You never too young to learn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top