I have an access application with a vba backend and it opens a word document to enter information and then print the word document and should close it.
I keep getting an error on the line "objword.ActiveDocument.Close wdDoNotSaveChanges......can anyone please help me on this and shed some light on why this is not working. Here is my code.
- Public Sub PrintWarningOne()
-
On Error GoTo MergeButton_Err
-
-
Dim objWord As Word.Application
-
-
'Start Microsoft Word 07.
-
Set objWord = CreateObject("Word.Application")
-
-
With objWord
-
'Make the application visible.
-
.Visible = True
-
-
'Open the document.
-
.Documents.Open ("C:\BookMarkWarning.docx")
-
-
'Move to each bookmark and insert text from the form.
-
.ActiveDocument.Bookmarks("Violation").Select
-
.Selection.Font.Color = vbRed
-
.Selection.Font.Bold = True
-
-
If Forms!frm_Input_frm![2ndWarning] = True Then
-
.Selection.Text = ("2nd WARNING!")
-
Else
-
.Selection.Text = ("WARNING!")
-
End If
-
-
.ActiveDocument.Bookmarks("FirstName").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!RegisteredFirst))
-
.ActiveDocument.Bookmarks("LastName").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!RegisteredLast))
-
.ActiveDocument.Bookmarks("Address").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!Address))
-
.ActiveDocument.Bookmarks("City").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!City))
-
.ActiveDocument.Bookmarks("State").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!State))
-
.ActiveDocument.Bookmarks("Zip").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!ZipCode))
-
.ActiveDocument.Bookmarks("Tag").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!TagNumber))
-
.ActiveDocument.Bookmarks("TagState").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!StateTag))
-
.ActiveDocument.Bookmarks("Make").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!VehicleMake))
-
.ActiveDocument.Bookmarks("Model").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!VehicleModel))
-
.ActiveDocument.Bookmarks("Color").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!VehicleColor))
-
.ActiveDocument.Bookmarks("Violator").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!Violator))
-
.ActiveDocument.Bookmarks("Location").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!Location))
-
.ActiveDocument.Bookmarks("Intersection").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!IntersectStreet))
-
.ActiveDocument.Bookmarks("Date").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!Date))
-
.ActiveDocument.Bookmarks("Time").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!Time))
-
.ActiveDocument.Bookmarks("Debris1").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!DebrisType1))
-
.ActiveDocument.Bookmarks("Debris2").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!DebrisType2))
-
.ActiveDocument.Bookmarks("DebrisNote").Select
-
.Selection.Text = (CStr(Forms!frm_Input_frm!DebrisNotes))
-
-
End With
-
-
'Print the document in the foreground so Microsoft Word will not close
-
'until the document finishes printing.
-
'objWord.ActiveDocument.PrintOut Background:=False
-
objWord.ActiveDocument.PrintOut False
-
-
'Close the document without saving changes.
-
'objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
-
objWord.ActiveDocument.Close wdDoNotSaveChanges
-
-
-
'Quit Microsoft Word and release the object variable.
-
objWord.Quit
-
Set objWord = Nothing
-
Exit Sub
-
-
MergeButton_Err:
-
'If a field on the form is empty, remove the bookmark text, and
-
'continue.
-
If Err.Number = 94 Then
-
objWord.Selection.Text = ""
-
Resume Next
-
End If
-
-
Exit Sub
-
-
End Sub