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
  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 3650
NeoPa
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

1
7981
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
3
11300
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...
5
6697
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
4
3179
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
7
3893
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");
4
3255
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
4
8331
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...
14
5304
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;
2
4458
LegalIT
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...
0
9695
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,...
0
10902
Oralloy
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...
1
10642
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,...
0
9420
agi2029
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...
1
7824
isladogs
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...
0
7013
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();...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
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
3
3128
bsmnconsultancy
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.