polant
May 26 2012, 11:02 AM
Hi everyone
I want to print invoices on pre-printed continuous forms using an OKI ML 3320 dot matrix printer. At the moment we print the invoice using a report, but I realize that formatted reports and dot matrix printers are not a good match. I therefore want to discard the report and do all the printing using vba which will hopefully allow the OKI to work faster and more freely.
I have figured out just about everything. I use recordsets that give me all data required, for the invoice header / footer and invoice details. I managed to construct the columns of the invoice with right-alignment where necessary. I can also count pages and add 'Page m of n' on every page. To test everything, I write the output to a text file using
Open "MyTest.txt" For Output As #1
Print #1, "text goes here"
Print #1, "text goes here"
...
Print #1, "text goes here"
Close #1
What I do not know, is how do I send the data to the printer instead of the text file? What command should I use?
Additional info:
- Windows XP / Access 2003
- The OKI is not the default printer on the computer, there is also an HP Laser installed
- The port of the OKI is USB001.
This has given me a headache for 2 days now without any success. I hope someone can help me.
Doug Steele
May 26 2012, 11:11 AM
To be honest, I don't think it's possible (especially not for USB-connected printers).
RuralGuy
May 26 2012, 11:15 AM
I believe Windows still supports Logical Devices so have you tried:
Open PRN For Output As #1
You might also try just the Print statement which may just go to the printer:
Print "text goes here"
Print "text goes here"
...
Print "text goes here"
CyberCow
May 26 2012, 11:16 AM
Been there done that and got the headache to prove it.
What we did for getting report data to our OKI dot mattrix, was generate a report formatted to fit the OKI's pre-formatted 3-copy carb paper. It was a lot of trial and error, but I was eventually able to creae a report for the pre-designed papers. We must've gone through a whole reem of that paper stock, but when it was over, it was right. The report itself was pointed to the OKI printer directly, so the user never had to manually select the primter - as long as it was on line.
In our case, each report was never more than one page long, so we did not run into "next page" issues. We dropped the idea of sending text directly to the printer.
If yours requires "next page" configuring, then you approach is correct and you will indeed run into headaches, frustrations and much trial and error. I imagine though, you could experiment with page-breaks in the Access report design to get it work across multiple pages if needed.
hope this helps
polant
May 26 2012, 11:27 AM
Thanks guys for the quick responses.
@ Doug:
Should I consider changing the printer connection? If they still sell these things, there should be a way to use them.
@ RG
I tried
Print "text goes here"
unfortunately it gives me run-time error 438.
polant
May 26 2012, 11:38 AM
Cyber
QUOTE
What we did for getting report data to our OKI dot mattrix, was generate a report formatted to fit the OKI's pre-formatted 3-copy carb paper. It was a lot of trial and error, but I was eventually able to creae a report for the pre-designed papers. We must've gone through a whole reem of that paper stock, but when it was over, it was right. The report itself was pointed to the OKI printer directly, so the user never had to manually select the primter - as long as it was on line.
This is exactly what we now have in place, and it is working fine. Actually we have been printing the invoices using the hp laser (specified 2 copies in the report properties) but it was not a trouble free arrangement. For each invoice had to cut the tractor edges before we fed the paper to the printer. The paper is too thin for the laser, and it sometimes jammed.
With the OKI these problems are gone. However I feel that printing a formatted report is very hard work for the printer and thats why I am considering doing this change.
theDBguy
May 26 2012, 11:59 AM
Hi polant,
I don't know what you guys are talking about, so I may be asking the obvious here. If so, please forgive my ignorance.
If you can output the data into a text file in the proper format, then why can't you just send the text file to the printer?
Just curious...
polant
May 26 2012, 12:26 PM
Hi DBGuy
Yes, this is an option I have in mind.
In fact I tried to work with the text file and Notepad from Access with vba using object variables (in the same manner we work with a Word or Excel file from within Access) but I only managed to get various errors. As I understand, OLE automation (or whatever is called nowdays) cannot work with Notepad.
I am sure you know something I don't, so how should I go about sending the text file to the printer?
theDBguy
May 26 2012, 12:34 PM
Hi polant,
QUOTE (polant @ May 26 2012, 10:26 AM)

I am sure you know something I don't, so how should I go about sending the text file to the printer?
You can try using the ShellExecute() API with the "print" operation as argument.
Just my 2 cents...
Doug Steele
May 26 2012, 12:42 PM
No need for Automation.
Your initial code will already write to a text file (which is all Notepad is doing). You can then automate the printing by calling Notepad (or Wordpad), giving a command switch to do the printing. (Actually, there is a better way to automate the printing, but I'm afraid I don't remember it!):
CODE
Dim strCommand As String
strCommand = "notepad.exe /p ""mytext.txt"""
Shell strCommand
BTW, you're best off using a complete path for your file. If you don't, it will be written to the current directory, and you actually have no control over what Access thinks that is!
polant
May 26 2012, 01:10 PM
Thanks DBGuy and Doug
I have searched the internet about this, and ShellExecute appeared on a few occasions. As I do not have any other option at this stage, I will try it on Monday when I will have access to the printer.
The reasons I haven't tried it so so far is that:
- The OKI is not the default printer on the system. Can I specify a printer with ShellExecute?
- Although the paper size of our pre-printed stationery has been saved to OKI, the settings of the document sent for printing prevail, i.e. if we print a report specified as A4, OKI ignores its own settings and follows those of the report, ending up having the writing head half way through a pre-printed form. Unfortunately with Notepad, although you can change settings like printer and paper size, you cannot save them. Notepad always opens with the system's default settings which in this case are the HP laser and A4. If automation was possible, I would be able to change these settings with code and print the invoice properly.
The bottom line is that these dot matrix things are difficult to work with. Thats why I am looking at sending text directly to them.
Anyway, thank you all for your efforts, I will let you know how it goes.
zocker
May 26 2012, 07:48 PM
A bat file to send the textfile to the printer? I remember sending stuff direct to LPT1 and here are some details of the DOS print commands..
PRINT sending it to a usb non default printer will be interesting, I'd revert to a parallel port!
Let us know the outcome!
Zocker
polant
May 27 2012, 01:49 AM
After banging my head on the wall for a few hours last night, figured out a possible solution. Tried it this morning and IT WORKS!!
I decided to follow the direction suggested by theDBGuy and Doug Steele ,i.e. print the text file using Shell.
The problem was that Notepad opens with page setup settings (1) the default printer of the system, and (2) the paper size dictated by the default printer. I set the OKI as the default printer and everything worked perfectly.
However I could not leave permanently the OKI as the default printer on this machine, as the main printer used is the HP Laserjet. The final piece of the solution, was to find a way to programmatically set the OKI as the default printer prior to printing an invoice, then restoring the HP as the default. I found my solution in this
bytes.com topic. I downloaded the database and imported the class module into my application. Everything works perfectly now.
A big

to all of you guys! Your suggestions helped me finding a working solution.
ferreirah
May 27 2012, 09:38 AM
Hi
I also wanted to send text directly to a dot matrix printer.
There is a much better way to do this if you don't mind using api calls.
Have a look at the following Microsoft article on how to do this.
http://support.microsoft.com/kb/154078I think we should ask the UtterAccess people to store this link because it's such a usefull article.
H.F.
Doug Steele
May 27 2012, 10:15 AM
@ferreirah Why not write an article for the Wiki that points to that KB article?
Gustav
May 28 2012, 12:27 PM
At the stage you are now, the simply method is to write directly to the printer skipping the text file:
Open "LPT1" For Output As #1
Of course, the printer must be attached to the port either physically using the Centronics interface (parallel port) which most matrix printers have; or the LPT1 port (or other port you choose to use) must use a network printer:
Net Use LPT1 \\YourPrinterServer\ShareNameForTheOKI
This is way faster than anything else as it will drive the printer directly at its maximum printing speed.
The other option is to go back and redesign the report. Use the Generic Printer driver of Windows at least as a start, and design _any_ object (label, textbox) on the report using only monospaced fonts which the printer understands and always using a line spacing in parts of inches _exactly_ matching the font and printer.
Both methods are proven and "easy" (=nothing difficult to learn or understand) but - as you already have experienced - designing a report for a matrix printer requires amble time and patience. If you feel it takes two or three times the time you would expect, you are not alone.
Luckily, here we haven't had clients for years using matrix printers but I still recall those long days.
/gustav
polant
May 29 2012, 06:16 AM
Gustav
Many thanks for your suggestions which I will surely consider / try, as writing directly to the printer was my initial goal. As you mention, this will allow the printer to run at max. speed.
The code that writes the text file was quite tedious to build, but it should be straight forward to modify it to send the output to the printer. This is the first time I worked with a dot matrix printer, and I learned a few things on the way.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.