Microsoft KB Archive/252607

= PRB: The CopyFile Method Does Not Work for Printer DeviceName with Spaces on NT =

Article ID: 252607

Article Last Modified on 5/12/2003

-

APPLIES TO

 Microsoft Visual Basic 5.0 Learning Edition, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 2000 Standard Edition  Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft Visual Basic 5.0 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft Visual Basic 5.0 Enterprise Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 <li>Microsoft Windows 2000 Standard Edition</li></ul> </li> <li>Microsoft Visual Basic 6.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 2000 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q252607

<div class="symptoms_section">

SYMPTOMS
When a file is copied to the network printer with the CopyFile method of the FileSystemObject object, and the printer DeviceName contains a space, the following error occurs:

Runtime error 52: Bad file name or number

<div class="resolution_section">

RESOLUTION
If you have administrative privileges on the server, rename the printer so that the DeviceName is one word without spaces in it.

<div class="moreinformation_section">

MORE INFORMATION
Microsoft recommends that you do not have spaces in your printer DeviceNames because other problems might arise.

Step-by-Step Example
<ol> <li>On a Microsoft NT 4.0 system, add a printer with a name that contains a space.</li> <li>Create a text file in the C:\ folder, for example, test.txt.</li> <li>Start a new Standard EXE project in Visual Basic. Form1 is created by default.</li> <li>From the Project menu, select References, check Microsoft Scripting Runtime, and click OK.</li> <li>Add a CommandButton to the form.</li> <li> Paste the following code in the code window of Form1: Private Sub Command1_Click Dim FSO as FileSystemObject set FSO = new FileSystemObject

' To print on WinNT FSO.CopyFile "C:\test.txt", Printer.DeviceName

' If the devicename is like this: \\servername\HPLaser400, the file prints ' If the devicename is \\servername\HP Laser 400, the above mentioned ' run-time error occurs

' To print on Win9x ' FSO.CopyFile "C:\test.txt",Printer.Port End Sub </li> <li>Press the F5 key to run the project, and then click on the CommandButton.</li> <li>The file test.txt is printed if the DeviceName is one word without spaces.</li> <li>Alternatively, you can use APIs to bypass the printer driver and send data to the printer. This is documented in article Q154078 listed below in the "References" section.</li></ol>

<div class="references_section">