How to assign DEVMODE to report from API?

Unanswered How to assign DEVMODE to report from API?

  • 2012年8月9日 上午 11:57
     
     

    I'm trying to solve issue with reports in Access, where complex printing settings need to be applied to document on-fly. In short, users have option to define and save specific printout scenarios and then assign them to particular documents so that when they select print, depending on saved settings output will go to various printers, use various printing options and setting etc.

    All fine with collecting "printing scenarios" and saving them, all fine with even do the whole task, but somehow I believe going wrong path. Since application (front end) must be in compiled state (accde), there is no option to modify prtDevMode property (available only in design mode) and using provided Printer object and it's properties is also not an option, since many of the key settings are missing.

    At the very moment this process is done by modifying system printer properties through API (something like described here: http://support.microsoft.com/kb/230743 ) and then this printer is assigned to report being opened hidden, in preview mode and then simply sent to printing (all done from code). So, for user it is all transparent, works as expected, aside for few things: 1. It is very slow, which is to be expected. 2. There are issues with network printers and required rights (solvable, but still). 3. If anything goes wrong before system printer is returned to previous state, it is left with very specific settings, often wrong for "normal" use.

    Does anyone knows if it's possible to modify/set report's DEVMODE structure through API, instead of applying/copying DEVMODE structure to printer and then assigning printer to report? Or if anybody knows where would be right place to ask this question?

    I don't actually know why is prtDevMode read-only except for design mode, since it would normally get modified by using printing related dialogs or even I can freely modify any property of the Printer object, which will reflect in change of prtDevMode structure as well. But if I attempt to write it directly I can't, it's read-only...??? Was this some kind of "safety feature" by MS and is there a way to bypass it?

    Please help, even if only directing me to place with best chance to get an answer. Many thanks in advance

    Miroslav

所有回覆

  • 2012年8月13日 上午 06:26
    版主
     
     

    Hi Miroslav,

    Welcome to the MSDN forum!

    Please check this link to see if it helps:

    How To Modify Printer Settings with the DocumentProperties() Function
    http://support.microsoft.com/kb/167345 

    Using a DEVMODE structure to modify printer settings is more difficult than just changing the fields of the structure. Specifically, a valid DEVMODE structure for a device contains private data that can only be modified by the DocumentProperties() function. 

    This article explains how to modify the contents of a DEVMODE structure with the DocumentProperties() function.

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

  • 2012年8月13日 上午 10:07
     
     

    Dear Yoyo, thanks, I'm already doing it this way and it all works well, except it is

    1. Very, very slow (we are modifying system printer settings, use/apply them to report and then return to previous state afterwards)

    2. If anything goes wrong, system printer is left with very specific settings and other applications/users would be unaware of the change (printing with wrong settings)

    So my question is, is there any way to replace prtDevMode of an report on-fly (i.e. when report is in preview mode). We can't do it from Access directly, because it's read-only in preview mode, but is there maybe a way to use API?

    Miroslav

  • 2012年8月22日 上午 08:32
    版主
     
     

    Sorry about the late response.

    In my opinion, I'm afraid there is no such way via API. Hope someone else on this thread will be able to provide additional guidance.

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us