jackjohnson44
asked on
vb, ms word, and a printer problem
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.Applica tion")
With oWord
.Documents.add (App.path & "\RptStandard.dot")
.ActiveDocument.Bookmarks( "book1").S elect
.Selection.TypeText "type this"
ActivePrinter = frmMain.clsSetting.getSett ings("Prin terPassNam e") '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.BackgroundPrintingSt atus > 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.
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.Applica
With oWord
.Documents.add (App.path & "\RptStandard.dot")
.ActiveDocument.Bookmarks(
.Selection.TypeText "type this"
ActivePrinter = frmMain.clsSetting.getSett
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
While oWord.BackgroundPrintingSt
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.
ASKER
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ActivePrinter = frmMain.clsSetting.getSett
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?