MS Access Interop - How to set print filename?

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-05-24T15:56:55Z Indexed on 2010/05/24 16:01 UTC
Read the original article Hit count: 367

Filed under:
|
|
|

Hi all,

I'm using Delphi 2009 and the MS Access Interop COM API. I'm trying to figure out two things, but one is more important than the other right now.

I need to know how to set the file name when sending the print job to the spooler. Right now it's defaulting to the Access DB's name, which can be something different than the file's name. I need to just ensure that when this is printed it enters the print spool using the same filename as the actual file itself - not the DB's name. My printer spool is actually a virtual print driver that converts documents to an image.

That's my main issue. The second issue is how to specify which printer to use. This is less important at the moment because I'm just using the default printer for now. It would be nice if I could specify the printer to use, though.

Does anyone know either of these two issues? Thank you in advance.

I'll go ahead and paste my code:

unit Converter.Handlers.Office.Access;

interface

  uses
    sysutils, variants,
    Converter.Printer,
    Office_TLB, Access_TLB, UDC_TLB;

  procedure ToTiff(p_Printer: PrinterDriver; p_InputFile, p_OutputFile: String);

implementation

  procedure ToTiff(p_Printer: PrinterDriver; p_InputFile, p_OutputFile: String);
  var
    AccessApp : AccessApplication;
  begin
    AccessApp := CoAccessApplication.Create;
    AccessApp.Visible := False;

    try
      AccessApp.OpenCurrentDatabase(p_InputFile, True, '');
      AccessApp.RunCommand(acCmdQuickPrint);
      AccessApp.CloseCurrentDatabase;
    finally
      AccessApp.Quit(acQuitSaveNone);
    end;
  end;

end.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about interop