473,837 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why won't my word document save changes

37 New Member
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.Active Document.Close wdDoNotSaveChan ges......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
  4.     Dim objWord As Word.Application
  6.     'Start Microsoft Word 07.
  7.     Set objWord = CreateObject("Word.Application")
  9.     With objWord
  10.         'Make the application visible.
  11.         .Visible = True
  13.         'Open the document.
  14.         .Documents.Open ("C:\BookMarkWarning.docx")
  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
  21.         If Forms!frm_Input_frm![2ndWarning] = True Then
  22.             .Selection.Text = ("2nd WARNING!")
  23.         Else
  24.             .Selection.Text = ("WARNING!")
  25.         End If
  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))
  66.     End With
  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
  73.     'Close the document without saving changes.
  74.     'objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
  75.     objWord.ActiveDocument.Close wdDoNotSaveChanges
  78.     'Quit Microsoft Word and release the object variable.
  79.     objWord.Quit
  80.     Set objWord = Nothing
  81.     Exit Sub
  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
  91.     Exit Sub
  93. End Sub
Oct 19 '09 #1
1 3650
32,584 Recognized Expert Moderator MVP
What's the line # & what's the error message?
Oct 19 '09 #2

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

Similar topics

by: Eager-Learner | last post by:
Through window.open or window.showmodaldialog, I want to open a word or excel document in Print Preview mode. Bcos I don't want the user to make any changes or save it but the user can ONLY VIEW OR take a print out. Can anyone help me out ? Thanks in advance for any help / guideline
by: Brian Kwan | last post by:
Project Description: Develop a web application to help manage sale operations. There is a function that to generate a report using data in database, which is a Word document on server and let user to download and print it out. Problem: Found that it's risky to do Word automation on server side using ASP. The layout of report is a bit complicated. I've a idea of ASP call VB to automate a Word document, but don't know whether it's work or...
by: John Smith | last post by:
Hey folks, I'm creating an MS Word document in a C# Windows application. Because the client base has so many different versions of Word they are using, I opted to go with late binding to create the document. **Everything works great, but I can't figure out how to do 2 things: 1) Double Spacing 2) Insert a Page Break
by: Andrew Inwards | last post by:
Is it possible to save a MS Word document in a string? I suspect not because Ive tried saving it in using various encoding formats and it always gets corrupted. Thanks Andrew
by: Zeke | last post by:
I'm using the following code to create word document but the problem is if you go to task manager you'll see a WINWORD.EXE process is running but not the application, here is the code: Word.Document aDoc= WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible); WordApp.Visible = true; aDoc.Activate(); WordApp.Selection.TypeText("Hello");
by: Lisa | last post by:
Hi - I'm able to open excel workbooks and word documents, but I can't seem to copy excel charts, named ranges, etc. to a word document. Anyone know of good reference material in this area? What little documentation I've been able to find focuses on using only one office app at a time. Thanks for your help
by: Charlie Brookhart | last post by:
I am trying to write a code for a button click event. When the button is clicked, it is supposed to bring up an open file dialog box to allow the user to select the document they which to open. That word doucment will then be opened and displayed in MS Word. The code I have below doesn't quite work the way I expected it to. First, VB is complaining that the variable readOnly is not declared. How can that be when it is declared as Dim...
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
by: LegalIT | last post by:
Hello, I am a bit confused with using Word from VB.net. I would like to create a file name, then create a file with that file name. After the file is created I want to add a template. Since the template is from a server and used by multiple users I only want to add it. Then when the Word document is closed hopefully it won't ask if the user wants to save changes to the template. Can someone help me with the simple open, add the template...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.