I found a way to print to a file without being asked for a filename:
* Add a new printer that prints to the special "File:" port (see question 1).
* From the printers' panel, right click on the printer you have just added and select Properties.
* A panel showing the properties for this printer will pop up, click on the Details tab of this panel.
* Click on the Add Port... button.
* The Add Port panel will pop up, click on the Other radio button, and make sure Local Port is highlighted, click on OK.
* A small panel asking for the name of the port will pop up, enter the name of a file in the edit box, for example C:\Output.prn.
* Click on OK to dismiss the panel asking for the port name.
* Click on OK to dismiss the printer properties panel.
* If you now 'print' to this printer the output will be sent directly to C:\Output.prn (or wherever), overwriting what was there before.
But I need to modify the name of the file for each generated file but not interactively.
Has any one heard of an ocx by wich the filename can be set as a parameter ?
This is a slightly different approach, but you could use a dataport to export the data, and then use access to format the reports. It would be a two step approach, but would certainly work.
It is easy to get a dataport to create the file name for you on the fly, and even have it created in a specific directory.
Then set up an access routine to import, format and print your reports.
I do a lot of writing to text files, here is some boilerplate code I use:
First I set the filename, this can come from a field in a table if you like.
LogFileName :='\\Server\path\path\Sample.Log';
Now, open the file either for the first time or append to the end.
//Open files
IF EXISTS(LogFileName) THEN
BEGIN
LogFile.WRITEMODE:=TRUE;
LogFile.TEXTMODE:=TRUE;
LogFile.OPEN(LogFileName);
LogFile.SEEK(LogFile.LEN);
END
ELSE
BEGIN
LogFile.TEXTMODE:=TRUE;
LogFile.CREATE(LogFileName);
END;
Now at any point I can write to the file.
LogFile.WRITE( [data to write] );
Finally, I use this to close the file.
LogFile.CLOSE;
This works for me when I need to do special calculations or string concatenation.
Comments
It is the same as faxing, you cannot give the faxnumber from the customer to the printdriver.
Unless there is some trick/possibility in the printerdriver. What printerdriver are you using?
I am not sure if this is helpful. You want to print to a textfile. To my knowledge there is no printer driver that does not ask for a filename.
Another option is to print to PDF. A PDF printer that does not ask for a filename (if setup correctly) is PDFCreator. (Look for the auto-save options)
You can download this Printer Driver from: http://sourceforge.net/projects/pdfcreator/
Hope this helps you.
http://www.codegeniusstudio.com
http://www.facebook.com/CodeGeniusStudio
* Add a new printer that prints to the special "File:" port (see question 1).
* From the printers' panel, right click on the printer you have just added and select Properties.
* A panel showing the properties for this printer will pop up, click on the Details tab of this panel.
* Click on the Add Port... button.
* The Add Port panel will pop up, click on the Other radio button, and make sure Local Port is highlighted, click on OK.
* A small panel asking for the name of the port will pop up, enter the name of a file in the edit box, for example C:\Output.prn.
* Click on OK to dismiss the panel asking for the port name.
* Click on OK to dismiss the printer properties panel.
* If you now 'print' to this printer the output will be sent directly to C:\Output.prn (or wherever), overwriting what was there before.
But I need to modify the name of the file for each generated file but not interactively.
Has any one heard of an ocx by wich the filename can be set as a parameter ?
Any ideas ?
Thanks.
It is easy to get a dataport to create the file name for you on the fly, and even have it created in a specific directory.
Then set up an access routine to import, format and print your reports.
First I set the filename, this can come from a field in a table if you like.
LogFileName :='\\Server\path\path\Sample.Log';
Now, open the file either for the first time or append to the end.
//Open files
IF EXISTS(LogFileName) THEN
BEGIN
LogFile.WRITEMODE:=TRUE;
LogFile.TEXTMODE:=TRUE;
LogFile.OPEN(LogFileName);
LogFile.SEEK(LogFile.LEN);
END
ELSE
BEGIN
LogFile.TEXTMODE:=TRUE;
LogFile.CREATE(LogFileName);
END;
Now at any point I can write to the file.
LogFile.WRITE( [data to write] );
Finally, I use this to close the file.
LogFile.CLOSE;
This works for me when I need to do special calculations or string concatenation.