Solved

CommonDialog printing

Posted on 1998-06-11
6
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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