Solved

vb, ms word, and a printer problem

Posted on 2004-08-29
6
150 Views
Last Modified: 2010-05-02
Hello,
I have a vb program that opens a word template, changes it, prints it in the background, then closes it.

For some reason, when this is run on a specific machine that uses word 2000, (I don't know if it matters)
it gives an error when I set the printer to a printer name.  This works all the time on most machines.  It only works once on another,  I have to restart to set the printer again.

Here is my code:

Set oWord = CreateObject("Word.Application")

With oWord
      .Documents.add (App.path & "\RptStandard.dot")

      .ActiveDocument.Bookmarks("book1").Select
      .Selection.TypeText "type this"

      ActivePrinter = frmMain.clsSetting.getSettings("PrinterPassName")  'this gives the right printer name, I am sure

      If err.Number <> 0 Then                'this error happens the second time I run this function
            MsgBox "There was an error selecting the printer, the document will not print."      
      Else
            .ActiveDocument.PrintOut Background:=True
      End If

      oWord.ActiveDocument.Saved = True

      While oWord.BackgroundPrintingStatus > 0
            DoEvents
      Wend

      oWord.ActiveDocument.Close
      oWord.Quit

End With


I have another form that pops up a window with all avalible printer names.  for some reason, it won't work after I run this function the second time.  It seems like for some reason, the printer can't be found.
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 7

Expert Comment

by:_agj_
ID: 11929113
i have  a feeling the error is only due to the implementation of your:

     ActivePrinter = frmMain.clsSetting.getSettings("PrinterPassName")

in the sense, how is this clsSetting implemented.....
step through the relevant code. I guess you will find that it doesnt return a valid printer name each time it does a getSetting?
0
 

Author Comment

by:jackjohnson44
ID: 11931190
I have stepped through the code, it is the right name.  I am absolutely positive.  This can be changed to

 ActivePrinter = "Printer Name"      'printer name works, this is not the problem.


The second part of my problem is that I can't run code that lists the printer names after I run the above function once.  It has nothing to do with the name I am giving it.  I am absolutely positive of this fact.
0
 

Author Comment

by:jackjohnson44
ID: 11973630
I have found the solution, after much headache.

the correct syntax is

oWord.ActivePrinter =

not
ActivePrinter =

For some reason, leaving out the "oword" will work the first time you run the program, or it will work all the time if Outlook or Outlook express is open for some reason.  I haven't tested with applications other than outlook or outlook express.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12452091
Question answered by asker or dialog valuable.
Closed, 125 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question