jmbcreative
Technical User
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?
******************
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?