views:

85

answers:

1

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.
+2  A: 

Microsoft has issued a Hot Fix for saving the Page Setup Dialog Settings. That may affect your code.

Printers can be controlled through

  • AccessApp.Printers
    • All List of all available Printers and settings
  • AccessApp.Printer
    • Ability to set the current printer to use or adjust the settings of the current printer.

I am not familiar with your printer driver so I can't try to set the filename.

Robert Love
Great response. Thank you. Unfortunately I don't see any way to set the resulting filename in the printer spool - it's still using the Access DB Name.
Ryan