Solved

CommonDialog printing

Posted on 1998-06-11
6
165 Views
Last Modified: 2010-05-03
Ok, this is a really simple problem, but I'll be damned if I can get it to work...

OK, I have a text file, called "am.txt" that I want to print from a VB program. I don't want to open it, I just want to print it to the default windows printer.

I've created a form with a Common Dialog box control, and a button. In the click event of the button is the following code:
     commondialog1.filename="c:\am.txt"
     commondialog1.action=5 '//The print dialog

Now, this displays the print dialog, but when I click on OK, nothing happens.

What have I missed?

Dan

p.s The default printer is a networked HP LaserJet 5N.
0
Comment
Question by:FaffMan
6 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1463086
Dan

The common dialog control does not print.....  It sets up printing

use the printer object for printing
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463087
FaffMan,
The commonDialog only allow you to select the parameters for printing, such as printer, number of copies. It does not actually send the data to the printer. You need to write the code as to how you want your file.
One simple way is to set the PrinterDefault property to true and use the Printer object.
If you have more questions, let me know.
Regards
Dalin
0
 

Author Comment

by:FaffMan
ID: 1463088
OK, so I tried the printer.print method, but I couldn't get that to work either.

If someone can give me some code that will actually print this text file, then I'll up the points to 100.

Dan



0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1463089
Dim hFile As Integer
Dim sText As String

hFile = FreeFile
Open "am.txt" For Input As hFile
Do Until EOF(hFile)
  Line Input hFile, sText
  Printer.Print sText
Loop
Printer.EndDoc
0
 

Author Comment

by:FaffMan
ID: 1463090
Nice one!

I'd actually got it working already, but my code took ages to print. Your code produces results a lot faster.

Dan


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463091
Glad I could be of help.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question