472,958 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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
  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 3574
32,547 Expert Mod 16PB
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...
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...
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...
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: ...
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...
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....
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...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.