Solved

CommonDialog printing

Posted on 1998-06-11
6
178 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

691 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