470,631 Members | 1,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Why won't my word document save changes

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.
Expand|Select|Wrap|Line Numbers
  1. Public Sub PrintWarningOne()
  2.     On Error GoTo MergeButton_Err
  3.  
  4.     Dim objWord As Word.Application
  5.  
  6.     'Start Microsoft Word 07.
  7.     Set objWord = CreateObject("Word.Application")
  8.  
  9.     With objWord
  10.         'Make the application visible.
  11.         .Visible = True
  12.  
  13.         'Open the document.
  14.         .Documents.Open ("C:\BookMarkWarning.docx")
  15.  
  16.         'Move to each bookmark and insert text from the form.
  17.         .ActiveDocument.Bookmarks("Violation").Select
  18.         .Selection.Font.Color = vbRed
  19.         .Selection.Font.Bold = True
  20.  
  21.         If Forms!frm_Input_frm![2ndWarning] = True Then
  22.             .Selection.Text = ("2nd WARNING!")
  23.         Else
  24.             .Selection.Text = ("WARNING!")
  25.         End If
  26.  
  27.         .ActiveDocument.Bookmarks("FirstName").Select
  28.         .Selection.Text = (CStr(Forms!frm_Input_frm!RegisteredFirst))
  29.         .ActiveDocument.Bookmarks("LastName").Select
  30.         .Selection.Text = (CStr(Forms!frm_Input_frm!RegisteredLast))
  31.         .ActiveDocument.Bookmarks("Address").Select
  32.         .Selection.Text = (CStr(Forms!frm_Input_frm!Address))
  33.         .ActiveDocument.Bookmarks("City").Select
  34.         .Selection.Text = (CStr(Forms!frm_Input_frm!City))
  35.         .ActiveDocument.Bookmarks("State").Select
  36.         .Selection.Text = (CStr(Forms!frm_Input_frm!State))
  37.         .ActiveDocument.Bookmarks("Zip").Select
  38.         .Selection.Text = (CStr(Forms!frm_Input_frm!ZipCode))
  39.         .ActiveDocument.Bookmarks("Tag").Select
  40.         .Selection.Text = (CStr(Forms!frm_Input_frm!TagNumber))
  41.         .ActiveDocument.Bookmarks("TagState").Select
  42.         .Selection.Text = (CStr(Forms!frm_Input_frm!StateTag))
  43.         .ActiveDocument.Bookmarks("Make").Select
  44.         .Selection.Text = (CStr(Forms!frm_Input_frm!VehicleMake))
  45.         .ActiveDocument.Bookmarks("Model").Select
  46.         .Selection.Text = (CStr(Forms!frm_Input_frm!VehicleModel))
  47.         .ActiveDocument.Bookmarks("Color").Select
  48.         .Selection.Text = (CStr(Forms!frm_Input_frm!VehicleColor))
  49.         .ActiveDocument.Bookmarks("Violator").Select
  50.         .Selection.Text = (CStr(Forms!frm_Input_frm!Violator))
  51.         .ActiveDocument.Bookmarks("Location").Select
  52.         .Selection.Text = (CStr(Forms!frm_Input_frm!Location))
  53.         .ActiveDocument.Bookmarks("Intersection").Select
  54.         .Selection.Text = (CStr(Forms!frm_Input_frm!IntersectStreet))
  55.         .ActiveDocument.Bookmarks("Date").Select
  56.         .Selection.Text = (CStr(Forms!frm_Input_frm!Date))
  57.         .ActiveDocument.Bookmarks("Time").Select
  58.         .Selection.Text = (CStr(Forms!frm_Input_frm!Time))
  59.         .ActiveDocument.Bookmarks("Debris1").Select
  60.         .Selection.Text = (CStr(Forms!frm_Input_frm!DebrisType1))
  61.         .ActiveDocument.Bookmarks("Debris2").Select
  62.         .Selection.Text = (CStr(Forms!frm_Input_frm!DebrisType2))
  63.         .ActiveDocument.Bookmarks("DebrisNote").Select
  64.         .Selection.Text = (CStr(Forms!frm_Input_frm!DebrisNotes))
  65.  
  66.     End With
  67.  
  68.     'Print the document in the foreground so Microsoft Word will not close
  69.     'until the document finishes printing.
  70.     'objWord.ActiveDocument.PrintOut Background:=False
  71.     objWord.ActiveDocument.PrintOut False
  72.  
  73.     'Close the document without saving changes.
  74.     'objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
  75.     objWord.ActiveDocument.Close wdDoNotSaveChanges
  76.  
  77.  
  78.     'Quit Microsoft Word and release the object variable.
  79.     objWord.Quit
  80.     Set objWord = Nothing
  81.     Exit Sub
  82.  
  83. MergeButton_Err:
  84.     'If a field on the form is empty, remove the bookmark text, and
  85.     'continue.
  86.     If Err.Number = 94 Then
  87.         objWord.Selection.Text = ""
  88.         Resume Next
  89.     End If
  90.  
  91.     Exit Sub
  92.  
  93. End Sub
Oct 19 '09 #1
1 3413
NeoPa
32,301 Expert Mod 16PB
What's the line # & what's the error message?
Oct 19 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by John Smith | last post: by
4 posts views Thread by Andrew Inwards | last post: by
4 posts views Thread by Charlie Brookhart | last post: by
14 posts views Thread by Alan T | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.