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
- Microsoft Visual Basic 5.0 Professional Edition, when used with:
- Microsoft Windows NT 4.0
- Microsoft Windows 2000 Standard Edition
- Microsoft Visual Basic 6.0 Professional Edition, when used with:
- Microsoft Windows NT 4.0
- Microsoft Windows 2000 Standard Edition
- Microsoft Visual Basic 5.0 Enterprise Edition, when used with:
- Microsoft Windows NT 4.0
- Microsoft Windows 2000 Standard Edition
- Microsoft Visual Basic 6.0 Enterprise Edition, when used with:
- Microsoft Windows NT 4.0
- Microsoft Windows 2000 Standard Edition
This article was previously published under Q252607
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:
RESOLUTION
If you have administrative privileges on the server, rename the printer so that the DeviceName is one word without spaces in it.
MORE INFORMATION
Microsoft recommends that you do not have spaces in your printer DeviceNames because other problems might arise.
Step-by-Step Example
- On a Microsoft NT 4.0 system, add a printer with a name that contains a space.
- Create a text file in the C:\ folder, for example, test.txt.
- Start a new Standard EXE project in Visual Basic. Form1 is created by default.
- From the Project menu, select References, check Microsoft Scripting Runtime, and click OK.
- Add a CommandButton to the form.
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
- Press the F5 key to run the project, and then click on the CommandButton.
- The file test.txt is printed if the DeviceName is one word without spaces.
- 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.
REFERENCES
154078 HOWTO: Send Raw Data to a Printer Using the Win32 API from VB
Keywords: kbprb kbprint KB252607