Solved

VB5 and Printer.PaperBin

Posted on 1997-12-04
24
848 Views
Last Modified: 2008-02-01
Out of despiration I have upgraded to VB5 from VB4 because I couldn't get Crystal Reports to switch paper bins. So I tried to write the entire report in Visual BASIC instead. And after trying to write the program in VB4 I was informed by MicroSoft that the PaperBin property doesn't work in VB4. Now that I have VB5 I find that PaperBin still doesn't work right. I have sent mail to MicroSoft but don't expect a good reply any time soon. If anyone has a fix for this problem or knows of a service release that fixes it please let me know. Here is what I need to make work. (using APIs in place of this code is fine) I am doing this in Form_Load because I don't want any chance of anything being sent to the printer before this code runs. Any sample code you offer can be in any sub routine you like.

Private Sub Form_Load()
   Printer.PaperBin = 2      ' Lower Bin
   Printer.Print "Test Bin 2"
   Printer.NewPage
   Printer.PaperBin = 1      ' Upper Bin
   Printer.Print "Test Bin 1"
   Printer.EndDoc
End Sub

Everything works up to the point of the second PaperBin command. I then get an error stating 'PaperBin' can be set within a page. Even though I am not within a page.

This also happens with PaperSize, Orientation, and Duplex properties too.

Thanks in advance for any help that can be offered.
0
Comment
Question by:gwiz
24 Comments
 

Author Comment

by:gwiz
Comment Utility
Edited text of question
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
The following will do it:

   Printer.PaperBin = 2 ' Lower Bin
   Printer.Print "Test Bin 2"
   Printer.EndDoc
   Printer.PaperBin = 1 ' Upper Bin
   Printer.Print "Test Bin 1"
   Printer.EndDoc

0
 
LVL 3

Expert Comment

by:schworak
Comment Utility
That is a good idea unless you are going to be printing more than a few pages in that type of a situation. Since each EndDoc creates a new job in the print que it is likely that other jobs will get in the middle of yours and cause your job to fail.

I just found a vbprnt32.dll the other day. I haven't had time to try it out but it might be able to switch paper trays without ending the job. If you are interested, you should be able to find it on www.filepile.com.
0
 

Author Comment

by:gwiz
Comment Utility
It looks like the comment added by SCHWORAK was correct. I just tried it and it caused big problems.

The EndDoc idea is good when testing but when I used it with the real program it flooded my que and as this printer is shared by several computers, their jobs did get mixed in.

What I am doing is printing service bills. About 1500 a month on this program. The bill is to come out on special perferated paper from the top tray and the regular paper from the bottom tray. The other users are only using the bottom tray, but when their jobs get mixed in with the bills it would be really hard to hand sort it all out. And after the computer sent about 200+ jobs to the que at high speed, errors caused the program to fail. Some network que overload error came back.

Any other ideas? I am going to check out the mentioned DLL. thanks for that idea.
0
 

Author Comment

by:gwiz
Comment Utility
Is there still no way even in VB5 to talk directly to the printer driver?
0
 
LVL 4

Expert Comment

by:rantanen
Comment Utility
Just a thought based on what mrmick suggested...can you divide your print job into two jobs, first those going to the top bin and then those to the other one.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
From Microsoft Knowledge Base Article: Q85679...

The information in this article applies to:

 - Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

 - Microsoft Win32 Application Programming Interface (API) included with:

    - Microsoft Windows NT versions 3.5 and 3.51
    - Microsoft Windows 95 version 4.0
-------------------------------------------------------------------------

SUMMARY
=======

In Windows 3.1 and later, print settings can be changed on a page-by-page basis through the ResetDC() API.

MORE INFORMATION
================

An application can pass a new DEVMODE structure (containing new print settings) to ResetDC() between pages to change the print settings. For example, this function makes it possible to change the paper bin or paper orientation for each page in a print job. Note that ResetDC() cannot be used to change the driver name, device name, or the output port.

Before calling ResetDC(), the application must ensure that all objects (other than stock objects) that were previously selected into the printer device context are selected out.
...
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
Just for general information:  Yes there are ways to talk directly to the printer through API calls, however, not one of these addresses the issue of changing paper trays. I think mick's on the right track with the ResetDC.  Seems that Microsoft just figured we'd leave paper trays alone and let the printer handle it, because they sure didn't make it easy to work with.
0
 

Author Comment

by:gwiz
Comment Utility
That sounds exactly like what I need. Do you have any information on or an example of using the ResetDC command? I am looking throught the help files and docs provided with both VB4 and VB5 and can't find any mention of this one. If I can get this to work, you get the points of course! Thanks. I will keep looking for more info too.
0
 

Author Comment

by:gwiz
Comment Utility
Adjusted points to 165
0
 

Author Comment

by:gwiz
Comment Utility
Reply to rantanen: No, unfortunatly I can't easily split the job into two seperate jobs. our site will be processing the bills and get them ready for the mailing department on another floor. They refuse to sort two stacks of papers together. I am assuming they take the one large stack we provide and break it in to smaller stacks that several people process into the envelopes and ship out. So it might be too much work to try and break two stacks up into several sections and make sure all the parts stay together. That is my theory at least. They don't tell me everything. Until reciently this was all done on the same type of paper. But the price of the perferated paper has gotten so high and we will be using it on several new jobs that this is no longer a good way to work any more. Thanks for the suggestion though.
0
 

Author Comment

by:gwiz
Comment Utility
mrmick: could you give me the full number to that MS Knowladge base message you sent so I can read the rest of it and then grade your answer to this question?  Thanks!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 8

Expert Comment

by:mrmick
Comment Utility
That is the full number: Q85679

You won't find it using the whole site search offered on Microsoft's opening page... you must to go to Technical support or MSDN Online and do the search there.

The URL is:
http://premium.microsoft.com/support/kb/articles/q85/6/79.asp

However, I already pasted almost all of the content above.
0
 

Author Comment

by:gwiz
Comment Utility
Still trying to locate more info on using the ResetDC API. Unfortunatly I have had no luck. I just wanted you to know that I haven't forgotten about this question. MicroSoft's KB isn't much help either it seems.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
I can't remember if the Windows SDK came with VB4.  The info for the 16 bit stuff can be found there.  If it didn't come with VB4, I know for sure it came with VB3.  I've been developing with VB5 since it came out and no SDKs came with VB5.  If you can get your hands on the Win32 SDK, that would be your best bet.

You could probably say this question is answered though.

0
 

Author Comment

by:gwiz
Comment Utility
ARG!

I have been looking in to the ResetDC function. It uses the DEVMODE type. This type has a dmDefaultSource property that is used to change the default printer paperbin. (YEAH!)

The problem is as soon as you send anything to the printer, changing this property no longer changes the printer paperbin. It is only useful for setting the paperbin before printing starts. I can use the Printer.PaperBin for that. (Aaawwww...)

I have also been looking into the Escape API. It sounds like it was able to send commands to the printer such as changing paperbin or size and send escape codes directly to the printer driver. But the only documentation I can find is for the GDI version. Not the GDI32 version. And the GDI32 calls seems to do nothing. It doesn't even pass through the escape codes. (I tested by sending a page of text with no escape codes, then on a new document sent the same page with an added set of escape codes. The two files were the exact same size and printed exactly the same when released to the printer)

In any case, I am right back where I started. Thanks for your help even though nothing panned out yet. I will be sure to post the answer myself if I ever find one.
0
 

Author Comment

by:gwiz
Comment Utility
Adjusted points to 185
0
 

Author Comment

by:gwiz
Comment Utility
Adjusted points to 295
0
 
LVL 8

Accepted Solution

by:
mrmick earned 300 total points
Comment Utility
I would like to point out that according to the Q85679 (posted above as an answer) - it states:

SUMMARY
=======
In Windows 3.1 and later, print settings can be changed on a page-by-page basis through the ResetDC() API.

Note: "page-by-page basis"

This would indicate to me that you're answer is here.  May I see a fragment of your code including your usage of ResetDC and the DEVMODE structure?

0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
Something to check...

The ResetDC function does nothing between the StartPage and EndPage functions - in other words, you can only effectively call this function between pages.

The VB printer object has so many bugs, I don't know if this is an issue, so to make sure, I'd call the EndPage API function instead of the VB method just prior to attempting a call to ResetDC.

0
 

Author Comment

by:gwiz
Comment Utility
I will give the EndPage API and get back to you shortly. I am feeling under the weather so I won't be back to work for a while.  Thanks for all your help on this. I sure hope to get the answer soon.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
gwiz, what's your email address?
0
 

Author Comment

by:gwiz
Comment Utility
You can EMail me at g-wiz@g-world.com
I will have time tomorrow to give that EndPage thing a try by the way. I just got back to work today and I am a bit behind on other projects. Gotta love the flue!
0
 

Author Comment

by:gwiz
Comment Utility
Adjusted points to 300
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now