I need help with the following code. What I want to do is export the data from a access form to a word document. If all fields in the access form have data in them, then it will fill the word document completely. However, if the code see's one field in access with no data, then it will stop at that field in the word document. How can I export the data and skip the blank field?
Below is my code.
Private Sub cmdExportToWord_Click()
On Error GoTo cmdExportToWord_Err
Dim objWord As Word.Application
'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("C:\Path\Docname.doc")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
End With
'Save File with new name
objWord.ActiveDocument.SaveAs InputBox("Save As what file name? This file will save" & _
" under your My Documents folder:", "Save File")
cmdExportToWord_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
End If
End Sub