Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My code is changing the default printer when it shouldn't be!

Status
Not open for further replies.

slwolf8

Technical User
Apr 23, 2001
82
US
This is a very obscure problem but I am hoping someone can help. I have the following module in a Word XP global template that is located in the startup folder of everyone's machine here at my work. My code checks to see if a printer is installed (called "DPFPrint") on a user's machine by attempting to change the default printer to DPFPrint. If then changes back to their previous default printer. This code seems to work fine. However, users are reporting that their work is printing out to the DPFPrint printer when it shouldn't be. For instance, one user was printing out information from a website and it went to the DPFPrint printer instead of his local printer. Can anyone see anything wrong with my code that might cause that behavior?

Sub Auto()

Dim MySettings As Variant
MySettings = GetSetting(appname:="Printer", Section:="Docketing", Key:="Exists")
DPFPrinter = "DPFprint"
CurrentPrinter = Application.ActivePrinter

If MySettings = 1 Then
Documents.Add Template:=NormalTemplate.FullName
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
frmMain.Show
Else:
On Error Resume Next

Application.ActivePrinter = DPFPrinter
myPrinter = Left(Application.ActivePrinter, 8)

'Check to see if the docketing printer is installed

If myPrinter <> DPFPrinter Then
MsgBox &quot;You do not have the docketing printer installed. Please contact the Help Desk.&quot;
Exit Sub
End If

Application.ActivePrinter = CurrentPrinter

SaveSetting appname:=&quot;Printer&quot;, Section:=&quot;Docketing&quot;, Key:=&quot;Exists&quot;, setting:=1

Documents.Add Template:=NormalTemplate.FullName

If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If

frmMain.Show
End If

Documents.Add Template:=NormalTemplate.FullName

If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If

frmMain.Show

End Sub
 
Here's some more useful information. The old version of my macro did not cause this problem. Here is the code for that one:

Sub Auto()

On Error Resume Next

CurrentPrinter = Application.ActivePrinter

DPFPrinter = &quot;DPFprint&quot;

Application.ActivePrinter = DPFPrinter

myPrinter = Left(Application.ActivePrinter, 8)

'Check to see if the docketing printer is installed

If myPrinter <> DPFPrinter Then
MsgBox &quot;You do not have the docketing printer installed. Please contact the Help Desk.&quot;
Exit Sub
End If

Application.ActivePrinter = CurrentPrinter

Documents.Add Template:=NormalTemplate.FullName

If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If

frmMain.Show

End Sub
 
It may not be this code that's at fault. I can't figure out what it's actually supposed to be doing but as far as I can tell it always resets the user's active printer to its original setting.

Do you have any other code that changes the active printer? Do the users ever change the printer themselves? I suspect that could be where your problem lies and this function is therefore a red herring.

Nelviticus
 
As I look your code over, nothing really jumps out at me; but there are 2 small things that I would change.

Code:
        Application.ActivePrinter = DPFPrinter
        myPrinter = Left(Application.ActivePrinter, 8)
            
        'Check to see if the docketing printer is installed
        
        If [b]UCase(myPrinter) <> UCase(DPFPrinter)[/b] Then
            [b]Application.ActivePrinter = CurrentPrinter[/b]
            MsgBox &quot;You do not have the docketing printer installed.  Please contact the Help Desk.&quot;
            Exit Sub
        End If

When comparing strings I would make sure all characters are the same case (just to eliminate that possibility). Also, this if clause was the only place I saw that the current printer was not reset, so if myprinter <> DPFPrinter, then we really don't know what it is all we know is it isn't what we were looking for (so we should reset it just in case).

You mention that this runs in the startup folder. Does this run when windows starts or when Word XP starts? If it is when windows starts, maybe the DPFPrinter hasn't had a chance to connect yet? This is a long shot, but the only other thing I can think of right now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top